Сообщение WM_HELP

Const WM_HELP = &H53

Сообщение WM_HELP указывает, что пользователь нажал клавишу F1. Если меню активно, когда F1 нажата, WM_HELP посылается окну, связанному с меню; иначе, WM_HELP посылается окну, которое имеет фокус клавиатуры. Если никакое окно не имеет фокуса клавиатуры, WM_HELP посылается текущему активному окну

Возвращаемое значение

WM_HELP должен всегда возвращать 0

Параметры

wParam
Не используется - установлен в 0
lParam
Указатель к структуре HELPINFO, идентифицирующий элемент управления или другое окно

Пример

' 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

Категория

Окна