Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.

↑ Back to the top


More information

Perform the following steps in your Visual Basic application:
  1. Create a new project, Form1 is created by default. Add a few controls to the form.
  2. 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.
  3. 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
    
    					
  4. 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
    
    					
  5. Set the form's KeyPreview, WhatsThisHelp, and WhatsThisButton properties to TRUE.
  6. Set the HelpContextID property of each control on the form to a value from the help project file's MAP section.
  7. 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.

↑ Back to the top


References

Microsoft Visual Basic Help, version 4.0, 5.0

↑ Back to the top


Keywords: kbhowto, kbdsstools, KB189086

↑ Back to the top

Article Info
Article ID : 189086
Revision : 4
Created on : 7/1/2004
Published on : 7/1/2004
Exists online : False
Views : 421