vb6: how to click buttons on another running process?
using vb6 is it possible to click buttons and for开发者_高级运维ms on another running process programmatically ?
Look at the SendMessage()
API call. This is what Windows itself uses to notify a button it has been clicked.
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
E.g.
retval = SendMessage(hwndButton, BM_CLICK, ByVal CLng(0), ByVal CLng(0))
Tricky bit is getting the window handle of the button (hwndButton
). FindWindow()
and EnumChildWindows()
APIs will do this. FindWindow() will return the handle of the top-level windows (e.g. Notepad). Then EnumChildWindows can be used to iterate the controls until the correct button is found.
精彩评论