Solved

GetSubmenu API failing with IE 5.5

Posted on 2002-05-17
13
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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