Results 1 to 21 of 21

Thread: [RESOLVED] How to enumerate seperate program's menu items (of application running) in VB6

  1. #1

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Resolved [RESOLVED] How to enumerate seperate program's menu items (of application running) in VB6

    Hi again

    How to enumerate seperate program's menu items (of an application running) in VB6 ?

    i can enumerating caption - title and buttons but now i want to enumerate menus of an application running and i want to change them... is it possible

    see the previous thread i ve started:
    http://www.vbforums.com/showthread.php?t=561340
    if that help...

    thanks in advance

  2. #2

  3. #3

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    i want to replace with my text/caption/menus for helping user understand better a software or translate them to a different language... not for ever - while pressing a hotkey will be translated... when unpressed will come to first position... while it was

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    You can create and use a Resource file that contains all your text/caption/menus in different languages and then use the user's regional settings to determine which ones to show.

  5. #5

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    @MartinLiss i want to enumerate other's Application (exe) that will running already... for example Calculator of Windows.

    ps: by the way Realbasic is good language (better than vb6 for example in databases, direct3d, gui programming, webbrowser controls) or it is not ?

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    Quote Originally Posted by cyberd View Post
    @MartinLiss i want to enumerate other's Application (exe) that will running already... for example Calculator of Windows.

    ps: by the way Realbasic is good language (better than vb6 for example in databases, direct3d, gui programming, webbrowser controls) or it is not ?
    Sorry, I thought you were talking about your own application.

    I thought RealBasic was okay, and even though I wrote that article I didn't get into it very far and I don't use it now, so I can't comment on your examples.

  7. #7

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    Code:
    I didn't get into it very far and I don't use it now
    i understand...

    so anyone can help about enumerate other's Application (exe) menu that will running already...

  8. #8

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    i've found that code...

    that may be help... but until now i can't understand how it will work for me...

    http://allapi.mentalis.org/vbexample...&category=MISC

    can anyone help ?
    m o u t s k a

  9. #9
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    Looking at example now and it is almost what you need from what I can tell. I can also tell that you do not need the dll from the example as you are not going to be appending a menu to another program. I am trying to slowly work up an example for you that is a bit better explained.

  10. #10

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    @vb5prgrmr Thank you... i am waiting for your example - because i can't really understand those api's
    m o u t s k a

  11. #11
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    Okay, here we go....

    To use, start a new project, add a command button, and add the code
    Code:
    Option Explicit
    
    'constanst used for setting and retrieving the text/caption of windows
    Private Const WM_SETTEXT = &HC
    Private Const WM_GETTEXT = &HD
    Private Const WM_GETTEXTLENGTH = &HE
    
    Private Const MIIM_STATE = &H1
    Private Const MIIM_ID = &H2
    Private Const MIIM_SUBMENU = &H4
    Private Const MIIM_CHECKMARKS = &H8
    Private Const MIIM_TYPE = &H10
    Private Const MIIM_DATA = &H20
    
    Private Const MFT_STRING As Long = &H0
    
    Private Const MENU_IDENTIFIER As Long = &H1
    
    Private Type MENUITEMINFO
      cbSize As Long
      fMask As Long
      fType As Long
      fState As Long
      wID As Long
      hSubMenu As Long
      hbmpChecked As Long
      hbmpUnchecked As Long
      dwItemData As Long
      dwTypeData As String
      cch As Long
    End Type
    
    'used for finding an applications window
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    'used for determining if the handle returned by findwindow still exists
    Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
    
    'returns a handle to the menu from the window found by FindWindow
    Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    
    'returns the number of menu items of the menu found by GetMenu
    Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
    
    'returns the handle to a specific menu item
    Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    
    'returns true/false on success of filling a MENUITEMINFO structure with information
    Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As Long, lpMenuItemInfo As MENUITEMINFO) As Long
    
    'used for changing the properties of the menu item in question
    Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
    
    'returns a handle to the a sub menu from a menu item
    Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    
    
    Private Declare Function IsMenu Lib "user32" (ByVal hMenu As Long) As Long
    
    'the origional and the modified to make it easier to change the caption
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SendMessageSTRING Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    
    Dim OtherApplicationsWindowHandle As Long
    
    Private Sub Form_Load()
    
    On Error GoTo Form_LoadError
    
    'find notepad
    OtherApplicationsWindowHandle = FindWindow("notepad", vbNullString)
    
    'check to see if we have notepad
    If IsWindow(OtherApplicationsWindowHandle) = 0 Then
      
      'if we don't, shell it to start it
      Call Shell("notepad", vbNormalFocus)
      
      'now loop until we know that notepad is active
      Do Until IsWindow(OtherApplicationsWindowHandle) <> 0
        OtherApplicationsWindowHandle = FindWindow("notepad", vbNullString)
        DoEvents
      Loop
    End If
    
    Exit Sub
    Form_LoadError:
    
    MsgBox Err.Number & " " & Err.Description
    
    End Sub
    
    Private Sub Command1_Click()
    
    On Error GoTo Command1_ClickError
    
    Dim HandleToOtherWindowMenu As Long, MenuCount As Long, ReturnValue As Long
    Dim HandleToSubMenu As Long, SubMenuCount As Long
    Dim MII As MENUITEMINFO
    
    'grab the handle to the windows menu
    HandleToOtherWindowMenu = GetMenu(OtherApplicationsWindowHandle)
    
    'check to see if we have a valid handle
    If HandleToOtherWindowMenu = 0 Then
      MsgBox "Unable to find other applications menu", vbOKOnly + vbInformation, "Not Found"
      Exit Sub
    End If
    
    'just for giggles find out how many top level menu items we have
    MenuCount = GetMenuItemCount(HandleToOtherWindowMenu)
    
    'check to make sure we have menus
    If MenuCount < 0 Then
      MsgBox "Unalbe to get the count of menu items.", vbOKOnly + vbInformation, "No Count"
      Exit Sub
    End If
    
    'now set up the menu item info structure
    MII.cbSize = Len(MII)
    MII.fMask = MIIM_TYPE
    MII.fType = MFT_STRING
    
    MII.dwTypeData = vbNullString
    MII.cch = Len(MII.dwTypeData)
    
    'this first call may not fail but because we have set the buffer to a zero length string
    'the only thing we get back is the correct size of a buffer we need
    ReturnValue = GetMenuItemInfo(HandleToOtherWindowMenu, 0, True, MII)
    
    'then we use that information to set the size of the buffer + 1
    MII.dwTypeData = Space(MII.cch + 1)
    MII.cch = Len(MII.dwTypeData)
    
    'now retrieve the menu information (we want its caption
    ReturnValue = GetMenuItemInfo(HandleToOtherWindowMenu, 0, True, MII)
    
    'now we are going to set up the structure with the string we want to set the menu item to
    MII.dwTypeData = "&File Menu "
    MII.cch = Len(MII.dwTypeData)
    
    'after this call, you can check the running instance of notepad and see that it's caption
    'for the File menu item should read &File Menu
    ReturnValue = SetMenuItemInfo(HandleToOtherWindowMenu, 0, True, MII)
    
    'for giggles test to see if we were successful
    If ReturnValue = 0 Then
      MsgBox "Unable to change parent menu caption but will continue.", vbOKOnly + vbInformation, "No Joy!"
    End If
    
    'now get the sub menus to the file menu
    HandleToSubMenu = GetSubMenu(HandleToOtherWindowMenu, 0)
    
    'get the count of sub menus
    SubMenuCount = GetMenuItemCount(HandleToSubMenu)
    
    'reset the structure
    MII.dwTypeData = vbNullString
    MII.cch = Len(MII.dwTypeData)
    
    'make call to get the size of what the sturcture should be
    ReturnValue = GetMenuItemInfo(HandleToSubMenu, 8, True, MII)
    
    'set up the structrure with the size we need (you can pre do this ahead of time if you
    'want by making sure that the size of the string is definitly large enough to hold the
    'caption of the menu item)
    MII.dwTypeData = Space(MII.cch + 1)
    MII.cch = Len(MII.dwTypeData)
    
    'pull the data
    ReturnValue = GetMenuItemInfo(HandleToSubMenu, 8, True, MII)
    
    'set it with the text we want it displayed
    MII.dwTypeData = "E&xit Menu "
    MII.cch = Len(MII.dwTypeData)
    
    'make the call to change the E&xit sub menu of &File to E&xit Menu
    ReturnValue = SetMenuItemInfo(HandleToSubMenu, 8, True, MII)
    
    'check
    If ReturnValue = 0 Then
      MsgBox "Unable to change child menu caption.", vbOKOnly + vbInformation, "No Joy!"
    End If
    
    Exit Sub
    Command1_ClickError:
    
    MsgBox Err.Number & " " & Err.Description
    
    End Sub
    Now the counts are for retrieving how many menu items there are and you could use a for loop to enumerate through them to return the captions, just remember that while the count may be 5 it starts at zero 0 (0 to 4)

    This should get you very well started on completing the task of having a program that will change the menu captions to a different language or to whatever you want.

    Good Luck

  12. #12

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    RESPECT !!! you are writing well! and ofcourse right!!!!!!! the code changing by targeting the menuitem i want after targeting the window process i want!

    but as always... i read the very VERY VERY WELL documentation of your code... but i can't read the menus and submenus or something going bad...
    *** First i want to read the menuitem/submenus...

    please give me the snippet for like this:
    vb Code:
    1. for y=0 to menuitemcount-1
    2.  debug.print menuitem(y).caption
    3.  for x=0 to menuitem(x).submenu.count-1
    4.   debug.print ".." & menuitem(y).submenu(x).caption
    5.  next x
    6. next y

    or something - first i need to read if i want to translate...
    m o u t s k a

  13. #13
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    You have all the code you need to be able to accomplish what you want. You just need to modify it. You need to think about what you have, what you want to do, and think step by step on how to accomplish it. Now I have already given you the hints and the code you need to be able to enumerate through the top level menu items and each of their sub menu items and if necessary those sub items. Its all there!

    Place a break point at the beginning of the click event and step through the code reading the comments at each step and keep in mind my out of code comments at the end about looping through for retrieval. Then look at how the type is set up to retrive the information and set the information. You can do it, you have all the information you need between the code, the help files, and your own imagination.

    Good Luck

  14. #14

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Re: How to enumerate seperate program's menu items (of application running) in VB6

    Ok.. you have right... this forum can make me "lazy", something i didn't like all my life...
    THANKS AGAIN... RESPECT...
    I please moderators and administrators and all users reading that give you as much points they can if that counts for you!

    RESOLVED.
    m o u t s k a

  15. #15

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Re: [RESOLVED] How to enumerate seperate program's menu items (of application running

    vb Code:
    1. For armenu = 0 To MenuCount - 1
    2.    
    3.     'now set up the menu item info structure
    4.     MII.cbSize = Len(MII)
    5.     MII.fMask = MIIM_TYPE
    6.     MII.fType = MFT_STRING
    7.    
    8.     MII.dwTypeData = vbNullString
    9.     MII.cch = Len(MII.dwTypeData)
    10.    
    11.     'this first call may not fail but because we have set the buffer to a zero length string
    12.     'the only thing we get back is the correct size of a buffer we need
    13.    
    14.     ReturnValue = GetMenuItemInfo(HandleToOtherWindowMenu, armenu, True, MII)
    15.    
    16.     'then we use that information to set the size of the buffer + 1
    17.     MII.dwTypeData = Space(MII.cch + 1)
    18.     MII.cch = Len(MII.dwTypeData)
    19.    
    20.     'now retrieve the menu information (we want its caption
    21.     ReturnValue = GetMenuItemInfo(HandleToOtherWindowMenu, armenu, True, MII)
    22.     Debug.Print MII.dwTypeData
    23.    
    24.     'now get the sub menus to the file menu
    25.     HandleToSubMenu = GetSubMenu(HandleToOtherWindowMenu, armenu)
    26.    
    27.     'get the count of sub menus
    28.     SubMenuCount = GetMenuItemCount(HandleToSubMenu)
    29.    
    30.     For arsubmenu = 0 To SubMenuCount - 1
    31.    
    32.         'reset the structure
    33.         MII.dwTypeData = vbNullString
    34.         MII.cch = Len(MII.dwTypeData)
    35.        
    36.         'make call to get the size of what the sturcture should be
    37.         ReturnValue = GetMenuItemInfo(HandleToSubMenu, arsubmenu, True, MII)
    38.        
    39.         'set up the structrure with the size we need (you can pre do this ahead of time if you
    40.         'want by making sure that the size of the string is definitly large enough to hold the
    41.         'caption of the menu item)
    42.         MII.dwTypeData = Space(MII.cch + 1)
    43.         MII.cch = Len(MII.dwTypeData)
    44.        
    45.         'pull the data
    46.         ReturnValue = GetMenuItemInfo(HandleToSubMenu, arsubmenu, True, MII)
    47.        
    48.         Debug.Print MII.dwTypeData
    49.        
    50.     Next arsubmenu
    51.  
    52. Debug.Print
    53. Next armenu

    That will print Menus and first Submenus...

    but i can't make a multi-level check for more submenus - at least i can't make a clear code checker... is it possible to make one may be with a help of array ?
    m o u t s k a

  16. #16
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: [RESOLVED] How to enumerate seperate program's menu items (of application running

    Okay, here is a hint...

    Read the documentation on GetSubMenu especially the section where it says Return Values.

    Now with this knowledge, I hope you realize that you can test for either of these conditions (IF).

    Then look up the word recursion or recursive and if you have ever used the dir function recursively then you know where I am leading you, as walking the menu structure should be no different that walking a directory structure.

    Good Luck

  17. #17
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: [RESOLVED] How to enumerate seperate program's menu items (of application running

    Recieved you PM, busy at moment, but here is some psudo code to get you started
    Code:
    Private Sub/Function RecursiveMenuWalker(HandleToMenu As Long) As WhateverIfFuction
    Dim MenuCount As Long, ForLoopCounter As Integer
    Dim SubMenuCollection As New Collection
    
    MenuCount = GetMenuItemCount(HandleToMenu)
    
    For ForLoopCounter = 0 To MenuCount - 1
      HandleToSubMenu = GetSubMenu(HandleToOtherWindowMenu, ForLoopCounter)
      If HandleToSubMenu > 0 Then
        SubMenuCollection.Add HandleToSubMenu
      End If
      'do your other stuff...
    Next ForLoopCounter
    
    For ForLoopCounter = 1 To SubMenuCollection.Count
      RecursiveMenuWalker SubMenuCollection.Item ForLoopCounter 'may need to wrap collection with clng()
    Next ForLoopCounter
    
    End Sub/Function
    Now, as you can see from the above psudo code the initial calling sub/function passes the
    handle to the menu (HandleToOtherWindowMenu) Then this sub retrieves the count of menu items
    and starts to loop through it, all the while testing to see if that menu item has a submenu.
    Then if it does it adds the handle to the sub menu to a collection we can use later.
    From there you can do all the stuff you need to do to retrieve the caption of each menu item.
    Then when it is done with that loop it goes to the next loop where we have stored the handles
    to the sub menus. (Now, when it comes to the collection object you will need to look it up
    as I created this psudo code in notepad from memory. SO, DON'T take the above as actual code!)

    Now, the second loop calls this same sub (recursion) and passed the handles to the sub menus
    in and the process starts all over.

    Good Luck

  18. #18

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Re: [RESOLVED] How to enumerate seperate program's menu items (of application running

    I ve tried... i almost did it but in one level submenus... i think that my mind stopped ! can i have any help plz ?....

    my code:
    Code:
    Dim MenuCount As Long, ReturnValue As Long
    Dim HANDLETOSUBMENU As Long, SubMenuCount As Long
    Dim MII As MENUITEMINFO
    
    Dim armenu As Long
    
    
    For armenu = 0 To MenuCount - 1
        
        MII.cbSize = Len(MII)
        MII.fMask = MIIM_TYPE
        MII.fType = MFT_STRING
        MII.dwTypeData = vbNullString
        MII.cch = Len(MII.dwTypeData)
        ReturnValue = GetMenuItemInfo(HandleToOtherWindowMenu, armenu, True, MII)
        MII.dwTypeData = Space(MII.cch + 1)
        MII.cch = Len(MII.dwTypeData)
    
        ReturnValue = GetMenuItemInfo(HandleToOtherWindowMenu, armenu, True, MII)
        Debug.Print MII.dwTypeData
    
        RecursiveMenuWalker armenu
    
    Debug.Print
    Next armenu
    
    
    'the sub....
    
    Private Sub RecursiveMenuWalker(HandleToMenu As Long)
    
    Dim MenuCount As Long, ForLoopCounter As Long
    Dim HANDLETOSUBMENU As Long
    Dim MII As MENUITEMINFO
    Dim ReturnValue As Long
    
    Dim SubMenuCollection(100) As Long
        MII.cbSize = Len(MII)
        MII.fMask = MIIM_TYPE
        MII.fType = MFT_STRING
        
    HANDLETOSUBMENU = GetSubMenu(HandleToOtherWindowMenu, HandleToMenu)
    MenuCount = GetMenuItemCount(HANDLETOSUBMENU)
    
    If MenuCount <= 0 Then Exit Sub
    
    For ForLoopCounter = 0 To MenuCount - 1
      'HANDLETOSUBMENU = GetSubMenu(HandleToOtherWindowMenu, ForLoopCounter)
      'If HANDLETOSUBMENU > 0 Then
      '  SubMenuCollection(ForLoopCounter) = HANDLETOSUBMENU
      'End If
            MII.dwTypeData = vbNullString
            MII.cch = Len(MII.dwTypeData)
            ReturnValue = GetMenuItemInfo(HANDLETOSUBMENU, ForLoopCounter, True, MII)
            MII.dwTypeData = Space(MII.cch + 1)
            MII.cch = Len(MII.dwTypeData)
            ReturnValue = GetMenuItemInfo(HANDLETOSUBMENU, ForLoopCounter, True, MII)
            
            Debug.Print MII.dwTypeData
    
    Next ForLoopCounter
    
    'RecursiveMenuWalker HANDLETOSUBMENU
    
    'For ForLoopCounter = 0 To MenuCount - 1
      
      'RecursiveMenuWalker ForLoopCounter
      'If SubMenuCollection(ForLoopCounter) > 0 Then RecursiveMenuWalker SubMenuCollection(ForLoopCounter) 'may need to wrap collection with clng()
    'Next ForLoopCounter
    
    End Sub
    ...what to say... i am going to be 'a looser' ... :-( no i can't understand the construction of this API !!!
    m o u t s k a

  19. #19
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: [RESOLVED] How to enumerate seperate program's menu items (of application running

    Okay, I tried to use the code on microsoft word to demonstrait the recursive nature but the menu for it is actually a msoCommandBar, so if I ever pursue this in the future I'm going to have to figure something else out...

    On another note, I'm glad I saved this as a demo project...
    Code:
    Private Sub Command2_Click()
    
    On Error GoTo Command2_ClickError
    
    Dim HandleToOtherWindowMenu As Long, MenuCount As Long, ReturnValue As Long
    Dim HandleToSubMenu As Long, StopChar As String
    Dim MII As MENUITEMINFO, ForLoopCounter As Integer
    
    'grab the handle to the windows menu
    HandleToOtherWindowMenu = GetMenu(OtherApplicationsWindowHandle)
    
    'check to see if we have a valid handle
    If HandleToOtherWindowMenu = 0 Then
      MsgBox "Unable to find other applications menu", vbOKOnly + vbInformation, "Not Found"
      Exit Sub
    End If
    
    'just for giggles find out how many top level menu items we have
    MenuCount = GetMenuItemCount(HandleToOtherWindowMenu)
    
    'check to make sure we have menus
    If MenuCount < 0 Then
      MsgBox "Unalbe to get the count of menu items.", vbOKOnly + vbInformation, "No Count"
      Exit Sub
    End If
    
    'now set up the menu item info structure
    MII.cbSize = Len(MII)
    MII.fMask = MIIM_TYPE
    MII.fType = MFT_STRING
    
    For ForLoopCounter = 0 To MenuCount - 1
      
      MII.dwTypeData = vbNullString
      MII.cch = Len(MII.dwTypeData)
      
      'this first call may not fail but because we have set the buffer to a zero length string
      'the only thing we get back is the correct size of a buffer we need
      ReturnValue = GetMenuItemInfo(HandleToOtherWindowMenu, ForLoopCounter, True, MII)
      
      'then we use that information to set the size of the buffer + 1
      MII.dwTypeData = Space(MII.cch + 1)
      MII.cch = Len(MII.dwTypeData)
      
      'now retrieve the menu information (we want its caption)
      ReturnValue = GetMenuItemInfo(HandleToOtherWindowMenu, ForLoopCounter, True, MII)
      
      StopChar = Right(MII.dwTypeData, 1)
      Debug.Print Left(MII.dwTypeData, InStr(1, MII.dwTypeData, StopChar) - 1)
      
      'now get the sub menus to the file menu
      HandleToSubMenu = GetSubMenu(HandleToOtherWindowMenu, ForLoopCounter)
      
      'check to see if we have found a sub menu
      If HandleToSubMenu <> 0 Then
        
        'seems like this menu item has a sub menu so call the recursive menu walker
        RecursiveMenuWalker HandleToSubMenu, Left(MII.dwTypeData, InStr(1, MII.dwTypeData, StopChar) - 1)
        
      End If
      
    Next ForLoopCounter
    
    Exit Sub
    Command2_ClickError:
    
    MsgBox Err.Number & " " & Err.Description
    
    End Sub
    
    Private Sub RecursiveMenuWalker(ByVal SubMenuHandle As Long, ByVal ParentMenu As String)
    
    On Error GoTo RecursiveMenuWalkerError
    
    Dim SubMenuCount As Long, ForLoopCounter As Integer
    Dim HandleToSubMenu As Long, StopChar As String
    Dim MII As MENUITEMINFO, ReturnValue As Long
    
    'get the count of sub menus
    SubMenuCount = GetMenuItemCount(SubMenuHandle)
    
    'now set up the menu item info structure
    MII.cbSize = Len(MII)
    MII.fMask = MIIM_TYPE
    MII.fType = MFT_STRING
    
    For ForLoopCounter = 0 To SubMenuCount - 1
      
      'reset the structure
      MII.dwTypeData = vbNullString
      MII.cch = Len(MII.dwTypeData)
      
      'make call to get the size of what the sturcture should be
      ReturnValue = GetMenuItemInfo(SubMenuHandle, ForLoopCounter, True, MII)
      
      'set up the structrure with the size we need (you can pre do this ahead of time if you
      'want by making sure that the size of the string is definitly large enough to hold the
      'caption of the menu item)
      MII.dwTypeData = Space(MII.cch + 1)
      MII.cch = Len(MII.dwTypeData)
      
      'pull the data
      ReturnValue = GetMenuItemInfo(SubMenuHandle, ForLoopCounter, True, MII)
      
      StopChar = Right(MII.dwTypeData, 1)
      If StopChar <> "" Then
        Debug.Print ParentMenu & "." & Left(MII.dwTypeData, InStr(1, MII.dwTypeData, StopChar) - 1)
      Else
        If Trim(MII.dwTypeData) <> "" Then
          Debug.Print ParentMenu & "." & MII.dwTypeData
        Else
          Debug.Print ParentMenu & ".-menubar"
        End If
      End If
      'now get the sub menus to the file menu
      HandleToSubMenu = GetSubMenu(SubMenuHandle, ForLoopCounter)
      
      'check to see if we have found a sub menu
      If HandleToSubMenu <> 0 Then
        
        'seems like this menu item has a sub menu so call the recursive menu walker
        RecursiveMenuWalker HandleToSubMenu, ParentMenu & "." & Trim(MII.dwTypeData)
        
      End If
      
    Next ForLoopCounter
    
    Exit Sub
    RecursiveMenuWalkerError:
    
    MsgBox Err.Number & " " & Err.Description
    Resume
    End Sub
    Good Luck

  20. #20

    Thread Starter
    Lively Member cyberd's Avatar
    Join Date
    Jul 2008
    Location
    GREECE
    Posts
    108

    Re: [RESOLVED] How to enumerate seperate program's menu items (of application running

    msoCommandBar ... that is a problem... hmmm
    m o u t s k a

  21. #21
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: [RESOLVED] How to enumerate seperate program's menu items (of application running

    Yeah, that is the problem, but it does have children eventhough I have not had time to enumerate them to find out what they are...
    Option Explicit should not be an Option!

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