Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDisplay a message when the user opens a menu item
DescriptionThis example shows how to display a message when the user opens a menu item in Visual Basic 6. The program subclasses and watches for the WM_MENUSELECT message.
Keywordsmenu, status
CategoriesControls, API
 
The program subclasses and watches for the WM_MENUSELECT message. When it sees this message, it uses the GetMenuString API function to get the menu's caption and calls the form's ShowMenuTip method to display an appropriate message. The following code shows the new WindowProc.
 
' Look for WM_MENUSELECT.
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg _
    As Long, ByVal wParam As Long, ByVal lParam As Long) As _
    Long
Const WM_MENUSELECT = &H11F

Dim menu_id As Long
Dim menu_caption As String
Dim length As Long

    If msg = WM_MENUSELECT Then
        ' Get the menu ID.
        menu_id = (wParam And &HFFFF&)

        ' Get the menu caption.
        menu_caption = Space$(1024)
        length = GetMenuString(lParam, menu_id, _
            menu_caption, _
            Len(menu_caption), 0)
        menu_caption = Left$(menu_caption, length)

        Form1.ShowMenuTip menu_caption
    End If

    ' Invoke the old menu proc.
    NewWindowProc = CallWindowProc( _
        OldWindowProc, hwnd, msg, wParam, _
        lParam)
End Function
 
The following code show the form's ShowMenuTip routine.
 
' This routine could look up the caption
' and display a more descriptive message.
Public Sub ShowMenuTip(ByVal menu_caption As String)
    lblMenuTip.Caption = menu_caption
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated