|
-
Aug 23rd, 2012, 12:40 PM
#1
Thread Starter
Lively Member
SendMessage WM_GETTEXT LB_GETTEXT returns nothing
I have succesfully retrieved the handle of a control (which appears to be a list box) with the following code:
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Public Sub main()
Dim lngParent As Integer
Dim lngChild As Integer
Dim lngChild2 As Integer
Dim lngChild3 As Integer
Dim cReturn As Long, lParam As Long, parHwnd As Long
'I'm walking down the window tree until I find the control that I need
lngParent = FindWindow(vbNullString, "xxx- Home (Search)")
If lngParent <> 0 Then
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, "MDIClient", vbNullString)
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, vbNullString, "Home (Search)")
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, "AfxMDIFrame70", vbNullString)
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, "AfxFrameOrView70", vbNullString)
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, "SysTabControl32", vbNullString)
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, vbNullString, "Home")
ShowWindowInfo(lngParent)
lngChild = FindWindowEx(lngParent, 0, "GXWND", vbNullString)
ShowWindowInfo(lngChild)
lngChild2 = FindWindowEx(lngParent, lngChild, "GXWND", vbNullString)
ShowWindowInfo(lngChild2)
lngChild3 = FindWindowEx(lngParent, lngChild2, "GXWND", vbNullString)
ShowWindowInfo(lngChild3)
End if
End sub
Private Sub ShowWindowInfo(ByVal hWnd As Integer)
Dim lRet As Integer
Dim buffer As String
Dim message As String
Dim j As Integer
Dim wtext As String
Const WM_GETTEXT = &HD
Const LB_GETCOUNT = &H18B
wtext = Space(256)
j = SendMessage(hWnd, WM_GETTEXT, 255, wtext)
wtext = Left(wtext, j)
message = "Window handle: " & hWnd & vbCrLf
buffer = Space(256)
lRet = GetWindowText(hWnd, buffer, 256&)
message = message & "Window text: " & Left$(wtext, j) & " also: " & lRet & vbCrLf
buffer = Space(256)
lRet = GetClassName(hWnd, buffer, 256&)
message = message & "Class name: " & Left$(buffer, lRet) & vbCrLf
Debug.Print(message)
End Sub
The control I'm accessing appears to be a listbox but I monitored the messages using Window Detective and all I'm seeing is WM type messages when I click on the various elements. I was expecting WM_GETTEXT to return the string for the currently selected item, but it has always been empty. Any suggestions?
-
Aug 24th, 2012, 11:59 PM
#2
Lively Member
Re: SendMessage WM_GETTEXT LB_GETTEXT returns nothing
I do this as following:
1. hWndList is ListBox handle, you find it yourself.
2. Declare two messages: LB_GETCOUNT and LB_GETTEXT.
3. The code to get text of the current item:
PHP Code:
Dim index As Integer
Dim textBuff As String
textBuff = Space(255)
index = SendMessage(hWndList, LB_GETCOUNT, 0, 0)
SendMessage hWndList, LB_GETTEXT, i, textBuff
MsgBox textBuff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|