|
-
Nov 21st, 2005, 12:26 AM
#1
[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...
-
Nov 21st, 2005, 12:45 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 21st, 2005, 12:58 AM
#3
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.
-
Nov 21st, 2005, 01:09 AM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 21st, 2005, 01:34 AM
#5
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:
Dim intResult As Integer
intResult = win32.GetMenuItemID(hSubSubMenu, intMessageMenuIndex)
MsgBox(intResult.ToString) 'returns valid number, like "389"
Dim intresult2 As Integer
intresult2 = win32.SendMessage(hSubSubMenu, win32.WM_COMMAND, intResult, "")
MsgBox(intresult2.ToString) 'returns 0
'The function declaration I have for sendmessage, in seperate win32Functions class
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As String) As Int32
-
Nov 21st, 2005, 01:36 AM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 21st, 2005, 01:41 AM
#7
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:
Public Const WM_COMMAND As Int32 = &H111
Last edited by gigemboy; Nov 21st, 2005 at 01:44 AM.
-
Nov 21st, 2005, 01:50 AM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 21st, 2005, 01:57 AM
#9
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..
-
Nov 21st, 2005, 01:59 AM
#10
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 21st, 2005, 02:08 AM
#11
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.
-
Nov 21st, 2005, 02:13 AM
#12
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|