Reputation: 61
I am using VB6 to try and select a menu item in a sub menu of a third-party application. I can get the ID for the menu item I want to click but now I am not sure how to actually click the button in order to have the related actions run. Here is my code so far:
hwnd = FindWindow(psClassname, vbNullString)
If hwnd > 0 Then
Call SetForegroundWindow(hwnd)
mwnd = GetMenu(hwnd)
sub_menu = GetSubMenu(mwnd, 0)
button_ID = GetMenuItemID(sub_menu, 0)
Call SetFocus(button_ID)
I get the error:
Wrong number of arguments or invalid property assignment
I've also tried using:
Call SendMessage(button_ID, BM_CLICK, 0, 0)
but this didn't work either. Any ideas would be greatly appreciated!
Upvotes: 2
Views: 1339
Reputation: 16311
If you have the ID of the menu item, you can just send/post a WM_COMMAND
message to its parent that includes the ID. For example:
Private Const WM_COMMAND As Long = &H111
SendMessage hwnd, WM_COMMAND, button_ID, ByVal 0&
Upvotes: 2