|
-
Jun 25th, 2001, 05:46 PM
#1
Thread Starter
Hyperactive Member
API gurus only
I'm trying to use SendMessage to an app that has two "Edit" controls (TextBox). There is no way to tell them apart, so I can't send a message to one of them. I'm using a program called Spy++ which tells you the ClassName for anything inside an app. Any ideas on how I could tell them apart? Thanks.
[vbcode]
' comment
Rem remark
[/vbcode]
-
Jun 25th, 2001, 05:57 PM
#2
I'm no API guru, but this might help you
I'm no API guru, not even close, but I thought this might be helpful. You could try using a resource editor to look at the app, and the form you're looking for will be one of the resources. As far as I remember, if you look at the form in the resource editor, it will tell you the textfields' names.
-
Jun 25th, 2001, 06:02 PM
#3
Thread Starter
Hyperactive Member
Nope, that won't work with what I'm trying to do... I'm trying to get the text from a game, and the game has two Edit boxes that I cannot tell apart because they don't have window captions. Anything else?
[vbcode]
' comment
Rem remark
[/vbcode]
-
Jun 25th, 2001, 06:39 PM
#4
You can use the GetWindowLong() API with the GWL_ID flag to return the unique Control ID for the Window, i.e.
VB Code:
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_ID = (-12)
If GetWindowLong(lHwnd, GWL_ID) = lTheIDImLookingFor Then MsgBox "It's The One I Want!!"
-
Jun 25th, 2001, 07:25 PM
#5
Thread Starter
Hyperactive Member
ya but you see... there's TWO of the same control and all I can get is the ClassName for each one, and they both have the same ClassName. In Spy++, it looks like this:
[-] War2BNE
- "" ListBox
- "" ListBox
I need to know how to let VB know that I want to send a message to ONE of them. I cannot single them out by using just their ClassNames because they're the same... get it? Didn't think so... Any help plz?
[vbcode]
' comment
Rem remark
[/vbcode]
-
Jun 25th, 2001, 08:20 PM
#6
Yes, I Do get it, you just didn't understand my solution, each control (child hwnd) is assigned a unique identifier called the Control ID (check in Spy++ and you'll see it listed inthe Window properties tab), here's an example:
In a module:
VB Code:
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_ID = (-12)
Private lTextHwnd As Long
Private lMatchID As Long
Public Function FindTextboxHwnd(ByVal hWndOwner As Long, ByVal ID As Long) As Long
lTextHwnd = 0
lMatchID = ID
' Enumerate all Window within this Window
Call EnumChildWindows(hWndOwner, AddressOf EnumWindowProc, 0&)
FindTextboxHwnd = lTextHwnd
End Function
Private Function EnumWindowProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sClass As String
Dim lControlID As Long
' Extract this Windows Class name
sClass = Space(255)
sClass = Left(sClass, GetClassName(hwnd, ByVal sClass, 255))
' If the class is an Edit or Textbox, check it's ID
If InStr(LCase(sClass), "edit") > 0 Or InStr(LCase(sClass), "textbox") > 0 Then
'It's a Textbox
lControlID = GetWindowLong(hwnd, GWL_ID)
If lControlID = lMatchID Then
'This is the specific Textbox we want
lTextHwnd = hwnd
Exit Function
End If
End If
EnumWindowProc = hwnd
End Function
Example usage, (You would pass in the Window handle to the application and the ID of the specific control you want to get the handle for, the ID should always be the same for the specific control.)
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim lHwnd As Long
'Find the window handle for Textbox 2
lHwnd = FindTextboxHwnd(hwnd, 2)
SendMessage lHwnd, WM_SETTEXT, 8, ByVal "VB-World"
End Sub
... get it? Didn't think so...
such comments wouldn't normally yield you much in the way of results, but I thought others may benifit from the example also.
-
Jun 26th, 2001, 12:12 AM
#7
Registered User
Thanks for that information Aaron, I found it very useful
-
Jun 26th, 2001, 01:45 PM
#8
Thread Starter
Hyperactive Member
Thanks Aaron, by the way, I wasn't calling you stupid or anything, it's just that I know I'm TERRIBLE at explaining things. If I try to explain something to my mom, she usually doesn't understand me. Sorry if you took that offensively (sp.).
[vbcode]
' comment
Rem remark
[/vbcode]
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
|