Click to See Complete Forum and Search --> : Click a button with code?
josmond
Sep 21st, 1999, 08:11 PM
Does anyone know how to click a button using code. Probaly using the sendmessage command??
benski
Sep 21st, 1999, 08:14 PM
If it's a vb button, simply call the event procedure for that button!
For example, to click the cmdExit button on the current form use cmdExit_Click
josmond
Sep 22nd, 1999, 03:31 PM
It's another button in another application
Serge
Sep 22nd, 1999, 06:06 PM
If you know the Window Handle (hWnd) for that button then you can use SendMessage API to do that:
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_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const VK_SPACE = &H20
Public Sub ClickButton(hwnd As Long)
Call SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0)
Call SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0)
End Sub
Usage: ClickButton ButtonHwnd
Regards,
------------------
Serge
Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
WadeD
Jan 5th, 2000, 03:16 AM
I couldn't get Serge's code to work for a menu, though I'm using the correct menu handle (submenu actually).
Any ideas??
Thanks,
Wade
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.