Solved

GetSubmenu API failing with IE 5.5

Posted on 2002-05-17
13
451 Views
Last Modified: 2012-06-21
I'm trying to execute a IE menu from the code, obtaining first the top menu handle with GetMenu API (which works) then the menu item handle with GetSubMenu API (which works with say Notepad, but fails with IE) can anybody help with why GetSubMenu API with IE?

Here a code that I'm running

Dim hmirc As Long
Dim hMenu As Long
Dim hSubMenu As Long
Dim l As Long
Dim M As MENUITEMINFO
Dim SubmenuItem As Long

'this is the IE's main windows
hmirc = FindWindow("ieframe", vbNullString)

If hmirc > 0 Then
    hMenu = GetMenu(hmirc)
        If hMenu > 0 Then
            'Specifies Handle to the menu and the zero-            'based relative position in the specified
            'menu of an item that activates a drop-down
            'menu or submenu (THIS IS THE LINE THAT FAILS)
            hSubMenu = GetSubMenu(hMenu, SubmenuItem)
            If hSubMenu > 0 Then
                 M.fMask = MIIM_TYPE Or MIIM_ID
                 M.dwTypeData = Space$(128)
                 M.cbSize = Len(M)
                 M.cch = 128
                 l = GetMenuItemInfo(hSubMenu, 0, True, M)
                 'display menu item info if success
                 If l Then
                    MsgBox M.wID & "  " &  
                    Left$(M.dwTypeData, InStr _
                    (M.dwTypeData, Chr$(0)) - 1)
                 End If
                 'execute the menu item
                 l = SendMessage(hmirc, WM_COMMAND, _
                 M.wID, ByVal hSubMenu)
            End If
        End If
    End If
End Sub


THanks!
0
Comment
Question by:tbbrhun
  • 4
  • 4
  • 4
  • +1
13 Comments
 
LVL 2

Expert Comment

by:mirtol
Comment Utility
Explorer has a toolbar with a menu in it, so the menu you see at the top of the window doesn't belong to the window the same way as menus in simple apps such as notepad.

You'll have to look at the child windows of the explorer window until you find the toolbar window which is the menu toolbar.
0
 

Author Comment

by:tbbrhun
Comment Utility
mirtol:
THanks for your comment. I have already noticed it. But i CAN get handle to the menu, it's the submenu that i can't get. BTW, to get the menu handle I point GetMenu API to the main IE window (which is 'ieframe').
Thanks again.
0
 
LVL 2

Expert Comment

by:mirtol
Comment Utility
I have a little window snoop program I wrote on my computer,

Yes, the main IE window CLASS is 'IEFrame'

But this contains a 'ReBarWindow32' which contains a 'ToolbarWindow32' which holds the menu.

The fact that the main window has a menu handle associated with it is intriguing, but I daresay it isn't the handle of the menu you want. What error does the GetSubMenu function return?
0
 
LVL 2

Expert Comment

by:mirtol
Comment Utility
Sorry, insert a 'WorkerA' Classed window inbetween the 'IEFrame' and the 'ReBarWindow32'

Missed it first time.
0
 
LVL 2

Expert Comment

by:mirtol
Comment Utility
btw, on my computer the 'IEFrame' classed window has no menu handle....
0
 

Author Comment

by:tbbrhun
Comment Utility
mirtol:
I probably have a similar snoop program that shows me exactly similar children: 'WorkerW' (not 'WorkerA')then 'ReBarWindow32' then 'ToolbarWindow32'. Sorry to say, none of them returns handle to the menu. Only the 'IEFrame' does. speaking of GetSubMenu, it just returns zero (no handle). My IE version is 5.00.2920. I'm going to check if same true for 6.0. THANKS!
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Which menu do you want to call?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
By the way, i think this problem raises for every app that implements automation( excel, word, etc)
0
 

Author Comment

by:tbbrhun
Comment Utility
Richie:
I'm trying to execute the Save As menu off the File root. I know some people do it by sending keys, but I need to run the program in the backgroud, so SendKEys solution will not do. Thanks!
0
 
LVL 2

Expert Comment

by:ventond
Comment Utility
I am sure there is a menu handle on the form. But it is probably for the right-click pop up menus. You will have to drill into the toolbar to activate the menu item you want. A toolbar menu and a Menu are not the same thing.

0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
Comment Utility
That could be achieved with Automation.
There is a method of internetexplorer object/webbrowser control called ExecWb, with these parameters:
OLECMDID_SAVEAS,OLECMDEXECOPT_PROMPTUSER
If you need to know about automting IE or use webbrowser control take a look at:
www.angelfire.com/realm/vb-shared/index.html under "IE..." topic.
0
 

Author Comment

by:tbbrhun
Comment Utility
Richie: Thanks. I totally forgot about this method. It will do for now. Also, I'm willing to double the point if anyone can show me how to use OLECMDID_SAVEAS method with OLECMDEXECOPT_DONTPROMPTUSER parameter. I spent months looking for how to make it work.

Thanks again.

Brian
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Thanks for "A" grade.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now