2

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!

Bond
  • 16,071
  • 6
  • 30
  • 53
Matt26
  • 61
  • 4

1 Answers1

2

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&
Bond
  • 16,071
  • 6
  • 30
  • 53
  • That worked perfect for the menu items but it doesn't seem to be working when I am trying to send a message to a "ThunderRT6CommandButton". I have the correct ID for the Button and its parent. I'm trying the following code. SendMessage frame_id, WM_COMMAND, button_ID, ByVal 0& and then sleeping for 400ms after. Any ideas? – Matt26 Jul 24 '15 at 12:12
  • 1
    This question was about selecting a menu item. If you need to interact with other controls, submit a new question. Thanks. – Bond Jul 24 '15 at 12:20
  • SOLVED: Call SendMessage(button_ID, BM_CLICK, 0, 0) – Matt26 Jul 24 '15 at 13:04