VB6 Question

BitByter asked this question on 12/28/2011. It has been viewed 869 times, and is currently unresolved.

Disapprove Delete

Hello A few years ago I wrote a program to keep track of my win/loss ratio and other info on Freecell because
I did not care for the freecell info. The program used an API call, GetWindowText to get the current window
caption and from this text insert the game number into the program automatically.

For reasons only known to Microsoft the Freecell version in Windows 7 does not display the game number in
the window caption but in a strip at the bottom of the window. My question is does anyone know of an
API that would read this text?

Thanks for any help.

Stuart

Keywords:

Answer from FortyPoundHead on 12/28/2011

Disapprove Delete

I found this, it seems to be exactly what you are looking for. See the reference for usage.

Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Const WM_USER = &H400&
Const SB_GETTEXTLENGTH = (WM_USER + 3)
Const SB_GETPARTS = (WM_USER + 6)
Const SB_GETTEXT = (WM_USER + 2)

Private Sub ReadStatusBarText()
Dim hSbar As Long ' StatusBar window handle
Dim nParts As Long ' # of parts in SB
Dim i As Long ' part# index
Dim tLength As Long ' length of text
Dim xpBuffer As Long ' ptr to buffer in target process
Dim sBuffer As String ' our string copy

hSbar = &H42069C ' MY TEST CASE!!!

nParts = SendMessage(hSbar, SB_GETPARTS, 0, 0)
Debug.Print "SB has " & nParts & " parts"
If nParts < 1 Then Exit Sub

xpBuffer = drMemoryAlloc(hSbar, 256) ' assume texts are less than 256 bytes

For i = 1 To nParts
tLength = SendMessage(hSbar, SB_GETTEXTLENGTH, i - 1, 0)
'
' mask out the text-drawing style bits in the high word
' before using tLength
'
tLength = tLength And &HFFFF&
Debug.Print "txtlen(" & i & ") = " & tLength
If tLength > 0 And tLength < 256 Then
sBuffer = String$(tLength + 1, vbNullChar)
SendMessage hSbar, SB_GETTEXT, i - 1, xpBuffer
drMemoryRead xpBuffer, StrPtr(sBuffer), tLength
sBuffer = Left(StrConv(sBuffer, vbUnicode), tLength)
Debug.Print " txt = """ & sBuffer & """"
End If
Next
drMemoryFree xpBuffer
End Sub

Reference:http://www.xtremevbtalk.com/showthread.php?t=122191


Code Links