Results 1 to 12 of 12

Thread: [RESOLVED] Click Menu Item by Index

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Resolved [RESOLVED] Click Menu Item by Index

    I have the index number of a menuitem in a submenu, and the handle of the submenu, so now how can I click that menu item? Do I need to use SendMessage? Do I need to get the handle of the menuitem??

    Its all done through code, so Im not "clicking the menu items" individually in code, I am just navigating through the handles using the GetSubMenu api, then the GetMenuString for each item in the submenu to find the string I want. That gives me the index number, then I essentially need to initiate a click at that index number in the submenu...

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Click Menu Item by Index

    Well if your not actually clicking them then you can probably SendMessage with the proper wParam and lParam and WM_COMMAND message.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Click Menu Item by Index

    Then what can I do do get the handle of the menuitem by index number? I was using Getsubmenu to get the handle to the submenu... but how do I go about getting the individual menuitem handle of the item I want in the submenu?

    So right now I have a handle to the submenu containing the item I want to click, as well as the index number of the menu item... I can try to use SendMessage but I need to get past the step of getting that darn handle of the item I need..
    Last edited by gigemboy; Nov 21st, 2005 at 01:08 AM.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Click Menu Item by Index

    The wParam contains the menu item id. You can use the GetMenuItemID passing the menu handle and index number. Once you have the id you can pass it with SendMessage in the wParam with the WM_COMMAND message. I think that should do it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Click Menu Item by Index

    Hmm I tried it, but I'm getting zero for the return result of the sendmessage. I am getting a menuitem number, but when calling the sendmessage, I get nothing, which tells me that I might have a problem in the arguments or in the function declaration...
    VB Code:
    1. Dim intResult As Integer
    2. intResult = win32.GetMenuItemID(hSubSubMenu, intMessageMenuIndex)
    3. MsgBox(intResult.ToString) 'returns valid number, like "389"
    4. Dim intresult2 As Integer
    5. intresult2 = win32.SendMessage(hSubSubMenu, win32.WM_COMMAND, intResult, "")
    6. MsgBox(intresult2.ToString) 'returns 0
    7.  
    8. 'The function declaration I have for sendmessage, in seperate win32Functions class
    9. Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
    10.       ByVal hwnd As IntPtr, _
    11.       ByVal wMsg As Int32, _
    12.       ByVal wParam As Int32, _
    13.       ByVal lParam As String) As Int32

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Click Menu Item by Index

    Maybe there is some value needed in the lParam? 0?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Click Menu Item by Index

    Zero gives the same message, after switching the parameter declaration to int32 instead of string.... hehehe grrrrrrrr I love API (sarcastic)

    EDIT: The constant declaration for the WM_Command is below:
    VB Code:
    1. Public Const WM_COMMAND As Int32 = &H111
    Last edited by gigemboy; Nov 21st, 2005 at 01:44 AM.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Click Menu Item by Index

    Other then trying the WM_LBUTTONDOWN and WM_LBUTTONUP I am out of idea as i wonder if there is something missing in the message.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Click Menu Item by Index

    Thats what I was going to try, but I need the handle of the particular menu item I want instead of the menu handle..

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Click Menu Item by Index

    Oh, you know what, there is that codebank example by moeur on interacting with a 3rd party program's menu using subclassing of it and a C++ dll. Should be worth checking out.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Click Menu Item by Index

    Found it!! I was passing in the wrong window handle for SendMessage. It needs the Main Application Handle that contains the menu, not the handle of the submenu that contains the item you wish to click.

    Thanks alot as always, Rob... I'd rate ya, but it wont let me because apparently I need to spread more around

    **Edit - It did let me rate ya.. well how bout that... as if you needed any more.. hehe
    Last edited by gigemboy; Nov 21st, 2005 at 02:11 AM.

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Click Menu Item by Index

    No worries. I am glad that it worked and I knew something was missing. Bad Gigemboy *SLAP*

    It was only logic and reverse experience that I had on building a vb6 app entirely from APIs. No forms or controls. I created a menu from scratch and I remembered the message streams messages and logic. This is not the first time its come in handy.

    See ya in the VB.NET forum.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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