|
-
Mar 21st, 2003, 08:55 PM
#1
Thread Starter
Fanatic Member
How do I find a specific control's hWnd
I found this app's hWnd, but now I want to send a mouse click to 1 of the buttons on it, lets say AIM's warn button? or something, how would I find a specific hWnd of a button so I can send commands to it.
-
Mar 22nd, 2003, 04:15 PM
#2
Use Spy++ to find the child window structure to the "BUTTON" window class.
This will also give you all the window classes that are nested to the button.
Then use (depending upon the number of nested windows) FindWindowEx API(s)
to obtain the handel of the button you need.
Then SendMessage with the button handel and the BM_CLICK parameter
to simulate the click on the button.
-
Mar 22nd, 2003, 06:33 PM
#3
Thread Starter
Fanatic Member
hmm, How do I do this?
"Use Spy++ to find the child window structure to the "BUTTON" window class.
This will also give you all the window classes that are nested to the button."
I made a really simple API spy that gets the classname and hWnd that I use, using WindowFromPoint or w/e, anyway - the classname of the warn button is _Oscar_IconBtn, what do I do with this? If I need it
-
Mar 22nd, 2003, 06:52 PM
#4
Thread Starter
Fanatic Member
I got it, How do I find which button I need? right now it sends to the right most button (Send).. I want it to go to the left most button.
num2 = FindWindowEx(irc_hWnd, ByVal 0&, "_Oscar_IconBtn", vbNullString)
-
Mar 22nd, 2003, 07:00 PM
#5
If you have Visual Studio then its Microsoft Visual Studio 6.0 Tools - Spy++.
If not thenyou use the window classname in the FindwindowEx API.
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 Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, ByVal hWnd2 As Long,ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const BM_CLICK = &HF5
'handel 1 is the parent window handel.
'handel 2 is the child window (button)
'lpsz1 is the class name ("BUTTON")
'lpsz2 is the caption (if any) ("&Ok")
'This will return the handel to the button if found.
'Then ...
SendMessage hwndButton, BM_CLICK, 0&, 0&
-
Mar 22nd, 2003, 07:05 PM
#6
You need to add the button's caption to the FindWindowEx
Code:
num2 = FindWindowEx(irc_hWnd, ByVal 0&, "_Oscar_IconBtn", vbNullString)
To...
num2 = FindWindowEx(irc_hWnd, ByVal 0&, "_Oscar_IconBtn", "&Ok")
Then...
SendMessage num2 , BM_CLICK, 0&, 0&
-
Mar 22nd, 2003, 07:23 PM
#7
Thread Starter
Fanatic Member
Thanks, what if the caption is a graphic? just like a Open button and it has a pic of a new file? Like this warn button doesnt work if I use "&Warn", it mihgt be a graphic.
-
Mar 22nd, 2003, 08:12 PM
#8
The &Warn would be if the command button's caption had an accelerator shortcut key - Warn
So if not try "Warn"
On the other question its a bit more difficult.
What you need is to try to get the BUTTONs coordinates if the
form does not allow resizing then it will be the same all the time.
The to get the BUTTONs coordinates is to use -
Code:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
ALSO, GET THE NEXT BUTTON IF WRONG
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Const GW_HWNDNEXT = 2
You may have to get the handel of a control with a caption
nearby in order to test if the .Top or .Left coordinates are within
an accetable range for example
-
Mar 22nd, 2003, 11:12 PM
#9
Thread Starter
Fanatic Member
yeah I tried both, warn and &warn.
Thanks, will try this soon.
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
|