Provide Status Messages for Menus

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:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as