Solved

GetSubmenu API failing with IE 5.5

Posted on 2002-05-17
13
467 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
ID: 7017041
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
ID: 7017085
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
ID: 7017095
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
LVL 2

Expert Comment

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

Missed it first time.
0
 
LVL 2

Expert Comment

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

Author Comment

by:tbbrhun
ID: 7017133
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7017424
Which menu do you want to call?
0
 
LVL 16

Expert Comment

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

Author Comment

by:tbbrhun
ID: 7017524
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
ID: 7017685
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
ID: 7017880
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
ID: 7021611
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
ID: 7022199
Thanks for "A" grade.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 116
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 59
Advice in Xamarin 21 97
Export Data to Different .csv Files 26 115
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

820 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