Results 1 to 4 of 4

Thread: [RESOLVED] [2005] access the menu or directly access a method

  1. #1

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Resolved [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.

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  2. #2

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    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:
    1. WinAPI.SendMessage(hWndSubMenu, WinAPI.BN_CLICKED, 0, 0)

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  3. #3

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: [2005] access the menu or directly access a method

    ok now i'm really 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:
    1. 'the WM_COMMAND constant that you will need:
    2. Public Const WM_COMMAND As Int32 = &H111
    3. 'example
    4. 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

    VB Code:
    1. 'In the WinAPI module
    2. Public Const WM_COMMAND As Integer = &H111
    3. '************************************
    4.  
    5.         Dim hWndMainMenu As IntPtr = WinAPI.GetMenu(Est.MainWinHwnd)
    6.         Dim hWndMenu As IntPtr = WinAPI.GetSubMenu(hWndMainMenu, 1)
    7.         Dim MenuId As Integer = WinAPI.GetMenuItemID(hWndMenu, 1) 'returns 5
    8.  
    9.  
    10.         'THIS JUST WILL NOT CAUSE THE MENU TO BE CLICKED!!!
    11.         WinAPI.SendMessage(hWndMainMenu, WinAPI.WM_COMMAND, MenuId, 0)

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  4. #4

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    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...

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width