Results 1 to 3 of 3

Thread: [RESOLVED] How to detect the highlight of the Menu items (or mouse move over the Menu items)?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    29

    Resolved [RESOLVED] How to detect the highlight of the Menu items (or mouse move over the Menu items)?

    The Menus in VB6 have the only "Click" event. However when user moves mouse over the Menu items they become highlighted.

    Is it possible to somehow detect this "highlight" event of the menu items? Or at least to detect the move of mouse over the menu items?

    Thanks!

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,654

    Re: How to detect the highlight of the Menu items (or mouse move over the Menu items)

    You need to subclass the form, then you'll get the WM_MENUSELECT message when the item is highlighted. The LoWord of the wParam item contains the ID of the item, although with the items on a VB menu it's a little complicated since you don't assign the IDs yourself. One technique then is to, when the form loads, store the IDs in a public array:

    Code:
    Private Sub AssignMenuIDs()
    'Copies the item id numbers for the main menu bar
    Dim hMenu As Long
    Dim hSubMenu As Long
    Dim i As Long
    
    hMenu = GetMenu(Me.hWnd)
    
    'File menu- 14 items
    hSubMenu = GetSubMenu(hMenu, 0)
    ReDim midFile(13)
    For i = 0 To 13
        midFile(i) = GetMenuItemID(hSubMenu, i)
    Next i
    
    'and so on for other menus
    Then if I'm doing something like displaying a tip in a status bar,

    Code:
    Public Function F1WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    '[...]
        Select Case uMsg
    
            Case WM_MENUSELECT
                    szt = QueryMenuTip(LoWord(wParam))
                    Form1.StatusBar1.Panels(1).Text = szt
    '[...]
    End Function
    
    Public Function QueryMenuTip(idCmd As Long) As String
        If idCmd = midFile(0) Then QueryMenuTip = "Menu Item 1"
        If idCmd = midFile(1) Then QueryMenuTip = "Menu Item 2"
        If idCmd = midFile(2) Then QueryMenuTip = "Menu Item 3"
    '[....and so on]
    End Function

    Also, if you want to detect when the mouse moves over the main menu item itself, and not a subitem--eg File Edit etc, you would, still responding to WM_MENUSELECT, check If (HiWord(wParam) And MF_POPUP) = MF_POPUP Then the LoWord of the wParam in this case contains the position of menu, 0 for File, 1 for Edit, etc.
    Last edited by fafalone; Apr 4th, 2015 at 10:37 PM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    29

    Re: How to detect the highlight of the Menu items (or mouse move over the Menu items)

    Thank you very much!

Tags for this Thread

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