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.
Printable View
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.
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.
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
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)
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&
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&
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.
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 -
You may have to get the handel of a control with a captionCode: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
nearby in order to test if the .Top or .Left coordinates are within
an accetable range for example
yeah I tried both, warn and &warn.
Thanks, will try this soon.