Microsoft KB Archive/189086

= How To Create Context-Sensitive HTML Help in a Visual Basic App =

Article ID: 189086

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft HTML Help 1.3
 * Microsoft HTML Help 1.1
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q189086



SUMMARY
This article shows you how to implement context-sensitive HTML Help in a Visual Basic application.

Also, this article assumes that you have created an HTML Help (.chm) file to use with context-sensitive help.

For additional information on creating HTML help files, please see the following article in the Microsoft Knowledge Base:

191118 : How To Create Context-Sensitive HTML Help in an MFC Application

The information in this article is most useful for Visual Basic 4.0 and 5.0 applications. Visual Basic 6.0 has added support for HTML Help files that eliminates the need for calling the API directly. See Visual Basic's online help for more information.



MORE INFORMATION
Perform the following steps in your Visual Basic application:

 Create a new project, Form1 is created by default. Add a few controls to the form.  Add a module to the project, and add the following constants to the declaration section of the module:

Public Const HH_HELP_CONTEXT = &HF

Public Const MYHELP_FILE = "myfile.chm"

NOTE: "myfile.chm" is the path and name of the HTML Help file (.chm) you created earlier.   Add the following HTML Help API declaration to the module: Public Declare Function HtmlHelpLongArg Lib "hhctrl.ocx" _ Alias "HtmlHelpA" (ByVal hwndCaller As Long, _         ByVal pszFile As String, ByVal uCommand As Long, _          ByVal dwData As Long) As Long

  Intercept the form's KeyUp method to capture the F1 key using the following sample code in the Form KeyUp event procedure: Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer) dim iRetCode As Long If KeyCode = vbKeyF1 Then iRetCode = HtmlHelpLongArg(Me.ActiveControl.hWnd,_             MYHELP_FILE,HH_HELP_CONTEXT,Me.ActiveControl.HelpContextID) End If     End Sub

 Set the form's KeyPreview, WhatsThisHelp, and WhatsThisButton properties to TRUE. Set the HelpContextID property of each control on the form to a value from the help project file's MAP section. Run the Visual Basic application. Select a control on the form and press the F1 key. The appropriate context-sensitive help topic should appear on the screen.</li></ol>

<div class="references_section">