• Welcome to Valhalla Legends Archive.
 

Menu (Win32 API) Help Requested

Started by Grok, March 12, 2003, 05:16 AM

Previous topic - Next topic

Grok

Goal is to click a menu item in another application.

The Menu:  &Server  &Optical  &Whatever  S&tore

So far I've used GetMenu, GetMenuItemCount, and GetMenuString to find "S&tore" as the 4th item on the window's menu.

Do I need to click on S&tore to reveal its "submenu" and then get a handle to the submenu, so I can click on its item?

I want to click the last item in the submenu revealed by S&tore from the main menu.

Where do I go next?

Grok

OK, I have time to paste what I'm doing in more detail...

This is code so far...
   If gWnd.OSI.hwnd = 0 Then
        Dim hMenu As Long, lMenuCount As Long
        Dim sMenu As String, sMenuItem As String
        Dim lPos As Long
        hMenu = GetMenu(gWnd.NUTL.hwnd)
        If hMenu = 0 Then Exit Sub
        lMenuCount = GetMenuItemCount(hMenu)
        For lPos = 0 To lMenuCount - 1
            sMenuItem = String(30, 0)
            lRet = GetMenuString(hMenu, lPos, sMenuItem, 30, MF_BYPOSITION)
            lRet = HiliteMenuItem(gWnd.NUTL.hwnd, hMenu, 4, MF_BYPOSITION + MF_HILITE)
            If Len(sMenu) > 0 Then sMenu = sMenu & vbCrLf
            sMenu = sMenu & StripNulls(sMenuItem)
        Next lPos
        MsgBox "Menu items = " & vbCrLf & sMenu
        Exit Sub
    End If

This prints out
Menu items =
&Server
&Optical
O&bject
&Index
S&tore

Next I need to open S&tore's menu and click a particular item in that menu.

Skywing

You can send WM_COMMAND to the window to simulate a menu item hit.  Check out MSDN for full details, but I think it's what you're looking for.

Grok

#3
Yes thank you, but I'm trying to get the menu item number of the menu subitem off the 4-indexed menu item on the main menu.

The difficulty I'm having is with moving beyond the "top" menu (the one with the 5 items, 0-4).  I don't know how to open the "S&tore" menu to traverse its members.

Hmm, maybe GetMenuItem, GetSubMenu from there, then traverse those items to get the desired submenu's subitem id.  If I get positive results I'll post the solution.

Grok

Got it working now, but it doesn't return to VB from SendMessage until the user closes the dialog that was opened by the menu selection.  How can I fix that?

Dim hMenu As Long, hSubMenu As Long, hSubItem As Long

hMenu = GetMenu(gWnd.NUTL.hwnd)
hSubMenu = GetSubMenu(hMenu, 4)
hSubItem = GetMenuItemID(hSubMenu, 4)

lRet = SendMessage(gWnd.NUTL.hwnd, WM_COMMAND, hSubItem, 0&)

dxoigmn


Yoni

#6
SendMessage waits for the target to finish processing the message before it returns. If you want it to return immediately, use SendNotifyMessage instead. (Same prototype other than return value, which you can't retrieve since the function may return before the message finishes processing.)

Grok

#7
Thanks Yoni, works splendidly.
Dim hMenu As Long, hSubMenu As Long, hSubItem As Long
hMenu = GetMenu(gWnd.NUTL.hWnd)
hSubMenu = GetSubMenu(hMenu, 4)
hSubItem = GetMenuItemID(hSubMenu, 4)
lret = SendNotifyMessage(gWnd.NUTL.hWnd, WM_COMMAND, hSubItem, 0&)