Provide Status Messages for Menus

Subclassing a form lets you give a helpful message whenever a user highlights a menu item. Use the Caption property to identify the menu item, then display the help message in a label (lblStatus), which is on the form:

 ' --- Form codePrivate Sub Form_Load()	origWndProc = SetWindowLong(hwnd, GWL_WNDPROC, _		AddressOf AppWndProc)End SubPrivate Sub Form_Resize()	lblStatus.Move 0, ScaleHeight - lblStatus.Height, _		ScaleWidthEnd SubPrivate Sub Form_Unload(Cancel As Integer)	SetWindowLong hwnd, GWL_WNDPROC, origWndProcEnd Sub'--- Module codeType 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 LongEnd TypePublic Declare Function CallWindowProc Lib "user32" Alias _	"CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal _	hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, _	ByVal lParam As Long) As LongPublic Declare Sub CopyMemory Lib "kernel32" Alias _	"RtlMoveMemory" (hpvDest As Any, hpvSource As Any, _	ByVal cbCopy As Long)Public Declare Function GetMenuItemInfo Lib "user32" Alias _	"GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As _	Long, ByVal b As Boolean, lpMenuItemInfo As _	MENUITEMINFO) As LongPublic Declare Function SetWindowLong Lib "user32" Alias _	"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As _	Long, ByVal dwNewLong As Long) As LongPublic Const GWL_WNDPROC = (-4)Public Const WM_MENUSELECT = &H11FPublic Const MF_SYSMENU = &H2000&Public Const MIIM_TYPE = &H10Public Const MIIM_DATA = &H20Public origWndProc As LongPublic Function AppWndProc(ByVal hwnd As Long, ByVal Msg _	As Long, ByVal wParam As Long, ByVal lParam As Long) _	As Long	Dim iHi As Integer, iLo As Integer	Select Case Msg		Case WM_MENUSELECT			Form1.lblStatus.Caption = ""			CopyMemory iLo, wParam, 2			CopyMemory iHi, ByVal VarPtr(wParam) + 2, 2			If (iHi And MF_SYSMENU) = 0 Then				Dim m As MENUITEMINFO, aCap As String				m.dwTypeData = Space$(64)				m.cbSize = Len(m)				m.cch = 64				m.fMask = MIIM_DATA Or MIIM_TYPE				If GetMenuItemInfo(lParam, CLng(iLo), _					False, m) Then					aCap = m.dwTypeData & Chr$(0)					aCap = Left$(aCap, _						InStr(aCap, Chr$(0)) - 1)					Select Case aCap						Case "&Open": _							Form1.lblStatus.Caption = _							"Open a file"						Case "&Save": _							Form1.lblStatus.Caption = _							"Save a file"					End Select				End If			End If	End Select	AppWndProc = CallWindowProc(origWndProc, hwnd, Msg, _		wParam, lParam)End Function
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS