[RESOLVED] [2005] access the menu or directly access a method
ok here's what i'm doing automate an application... so far i've been able to start up the application and login using Win32 API calls... no problems thus far... however what i need to do next is access either the a specific method in the application or start the method by way of clicking the specific menu item.
the only problem is:
1. how can i get the handle to the menu item that i need to click to start this method up, because I can't seem to find the menu's handle... i've even tried spy++ and can't find it... ps the form is a mdi... if that makes any difference
or
2. is there a way that i can directly access the method that i need to call by way of the Win32 API?
any help would be appreciatd.
Re: [2005] access the menu or directly access a method
ok i finally was able to get the menu item that i need... but can i send message to... or should i say what do i need to send to that menu item to indicate it being clicked. i tried doing the following which didn't work
VB Code:
WinAPI.SendMessage(hWndSubMenu, WinAPI.BN_CLICKED, 0, 0)
Re: [2005] access the menu or directly access a method
ok now i'm really confused :confused:
ok after reading a post that gigemboy did
Quote:
Originally Posted by gigemboy
Menus are different, and need to be accessed using a different methodology, explained below...
There is a GetMenu API function that you can use, you pass it the window handle that contains the menu (Im guessing main FireFox window). That gives you a handle to the menu, where you would have to use GetSubMenu API in order to to access all the options in the menu, Ex. GetSubMenu(MenuHwnd, 0) gets the handle to the first column of menu items, the second column would be GetSubMenu(MenuHwnd, 1).
Once you get the handle to the submenu that contains the menu you wish to click, you can use GetMenuItemCount in order to get a count of the items, in case you need to loop, and GetMenuString in order to get the string of the menu item so you know which one you are working with.
Once you do that, you use GetMenuItemID passing in the SubMenu handle as well as the menu position number in the sub menu.
Once you have the menu item ID, its a matter of using SendMessage with the "WM_COMMAND" constant as well as the handle of the main window that contains the menu you wish to click, as well as the menu item ID mentioned previously, something like below:
VB Code:
'the WM_COMMAND constant that you will need:
Public Const WM_COMMAND As Int32 = &H111
'example
SendMessage(hWndMain, WM_COMMAND, MenuItemID, 0)
Hope this gives you an idea of where to start :) I did this originally in messing with menus in Yahoo Messenger, which is how I got the methodology down...
i did the following in my code i also just to make sure that i got the right menu/items, i did a GetMenuString to make sure i was getting the right menu. however this still doesn't work. can anyone tell me what i possibly could/am doing wrong :ehh:
VB Code:
'In the WinAPI module
Public Const WM_COMMAND As Integer = &H111
'************************************
Dim hWndMainMenu As IntPtr = WinAPI.GetMenu(Est.MainWinHwnd)
Dim hWndMenu As IntPtr = WinAPI.GetSubMenu(hWndMainMenu, 1)
Dim MenuId As Integer = WinAPI.GetMenuItemID(hWndMenu, 1) 'returns 5
'THIS JUST WILL NOT CAUSE THE MENU TO BE CLICKED!!!
WinAPI.SendMessage(hWndMainMenu, WinAPI.WM_COMMAND, MenuId, 0)
Re: [2005] access the menu or directly access a method
HAHA.... got it... i was sending the wrong handle.... wasn't even pay attention to my own code even after i posted it...
thanks anyway guys... :D