Results 1 to 4 of 4

Thread: Menu command

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    Hi,

    I've got the handle to a submenu that I wish to call. How can I use SendMessage to select it?

    I'm using:
    Call SendMessage(hSubMenu, &H100, 0, 0)

    but I'm not getting a response.

    Thanks in advance,
    Wade

  2. #2
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    Hi WadeD,

    Here's the code to select a Menu Item from a Window.

    To use it, create a new project and place 2 command buttons on it.

    In the VB Editor, paste the following:

    Code:
    Option Explicit
    
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetMenuItemID Lib "user32" (ByVal HMenu As Long, ByVal nPos As Long) As Long
    Private Declare Function GetSubMenu Lib "user32" (ByVal HMenu As Long, ByVal nPos As Long) As Long
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Hwindow As Long
    Private HMenu As Long
    Private HSubMenu As Long
    Private MenuID As Long
    
    Private Sub Command1_Click()
        SelectMenuItem "Calculator", 2, 2
    End Sub
    
    Private Sub Command2_Click()
        Unload Me
        End
    End Sub
    
    Private Sub SelectMenuItem(WinName As String, Level1 As Long, Level2 As Long)
        Hwindow = FindWindow(vbNullString, WinName)
        HMenu = GetMenu(Hwindow)
        HSubMenu = GetSubMenu(HMenu, Level1)
        MenuID = GetMenuItemID(HSubMenu, Level2)
        PostMessage Hwindow, &H111, MenuID, 0
    End Sub
    Be sure that you have "Calculator" open when you run it.

    All the best.

    Chris Jackson

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    This does work for calculator but not for the app that I'm calling. I know that I have the correct window and menu handles because I can get the menu text using these. Any ideas??

    Thanks,
    Wade

  4. #4
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    WadeD,

    Using the code I posted, make sure that you are typing in the title of the window correctly (including the correct Case). Also, keep in mind that the Menu Items and Sub Items begin with 0 and not 1. Finally, a "--------" (line) in a drop-down menu should be counted when you trying to access the menu choices.

    What's the name of the App that you are trying to access the Menu of anyway?

    Hope this helps.

    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width