WM_HELP Message

Platforms

Description & Usage

The WM_HELP message instructs a window to display context-sensitive help. This help could refer to the window itself, one of the controls on it, or a child window or dialog it created. The message includes a structure identifying the object which generated the message. While a window does not necessarily have to respond to the WM_HELP message by opening a WinHelp document, it ought to display help information of some kind.

Return Value

The WM_HELP message should always return a non-zero value.

Visual Basic-Specific Issues

None.

Parameters

wParam
Not used -- set to 0.
lParam
A pointer to a HELPINFO structure identifying the control or other window which originated the message.

Constant Definitions

Const WM_HELP = &H53

Example

' This code is licensed according to the terms and conditions listed here.

' Display an HTML document to provide help when the
' user clicks the "Help" button of a dialog box.  Notice how
' the WM_HELP message must be handled explicitly in
' this example, since Visual Basic does not allow you to create
' a handler through the interface.  Pay careful attention to where each
' piece of code must go.

' *** Place the following code in a module. ***
' This is a pointer to Form1's previous window procedure.
Public pOldProc As Long

' This is the handler for the WM_HELP message.
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Dim hi As HELPINFO  ' information about window requesting help
  Dim slength As Long  ' length of string
  Dim wintext As String  ' text of window calling for help
  Dim retval As Long  ' return value

  ' Decide which message has been received.
  Select Case uMsg
  Case WM_HELP
    ' Determine if the message box, having text "Warning!", is
    ' requesting help.  If so, display an HTML document for help.
    ' NOTE: in a "real" program, you should use the
    ' MessageBoxIndirect function because it
    ' allows a Context ID for a WinHelp file to be specified.  But
    ' since this is an example for WM_HELP, this inferior
    ' method is presented.
    
    ' Copy the information about the help message into the structure.
    CopyMemory hi, ByVal lParam, Len(hi)

    ' Determine the text of the window for which help is requested.
    slength = GetWindowTextLength(hi.hItemHandle) + 1
    wintext = Space(slength)
    retval = GetWindowText(hi.hItemHandle, wintext, slength)
    wintext = Left(wintext, retval)
    ' If it is "Warning!", open up the proper HTML document.
    If wintext = "Warning!" Then
      retval = ShellExecute(hwnd, "open", "C:\MyProg\mboxhelp.html", "", "", SM_RESTORE)
    End If
    
    ' Return successfully.
    WindowProc = 1
  Case Else
    ' Let the previous message handler process this message.
    retval = CallWindowProc(pOldProc, hwnd, uMsg, wParam, lParam)
    WindowProc = retval
  End Select
End Function

' *** Place the following code in the Form1_Load procedure. ***
' Set our custom window procedure as Form1's procedure.
pOldProc = SetWindowLong(Form1.hWnd, GWL_WNDPROC, AddressOf WindowProc)

' *** Place the following code in the Form1_Unload procedure. ***
' Set the previous procedure as the one Form1 uses (to make VB happy).
Dim retval As Long
retval = SetWindowLong(Form1.hWnd, GWL_WNDPROC, pOldProc)

' *** Place the following code wherever you want to invoke the message box.
' Prompt the user for a selection, allowing him to get help
' about his choice.
Dim mbresult As Long  ' result of message box
Dim flags As Long  ' message box's flags

flags = MB_YESNO Or MB_HELP Or MB_ICONWARNING
mbresult = MessageBox(Form1.hWnd, "Are you sure?", "Warning!", flags)
If mbresult = IDYES Then
  Debug.Print "You said 'Yes'"
Else
  Debug.Print "You said 'No'"
End If

Category

Windows

Back to the Message list.
Back to the Reference section.


Last Modified: January 31, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/w/wm_help.html