GetSubmenu API failing with IE 5.5

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!
tbbrhunAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Richie_SimonettiConnect With a Mentor IT OperationsCommented:
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
 
mirtolCommented:
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
 
tbbrhunAuthor Commented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mirtolCommented:
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
 
mirtolCommented:
Sorry, insert a 'WorkerA' Classed window inbetween the 'IEFrame' and the 'ReBarWindow32'

Missed it first time.
0
 
mirtolCommented:
btw, on my computer the 'IEFrame' classed window has no menu handle....
0
 
tbbrhunAuthor Commented:
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
 
Richie_SimonettiIT OperationsCommented:
Which menu do you want to call?
0
 
Richie_SimonettiIT OperationsCommented:
By the way, i think this problem raises for every app that implements automation( excel, word, etc)
0
 
tbbrhunAuthor Commented:
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
 
ventondCommented:
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
 
tbbrhunAuthor Commented:
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
 
Richie_SimonettiIT OperationsCommented:
Thanks for "A" grade.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.