You are currently offline, waiting for your internet to reconnect

How To Use HTML Help Text Popup Windows in a VBasic Program

This article was previously published under Q192118
This article has been archived. It is offered "as is" and will no longer be updated.
This article describes how to use HTML Help context-sensitive text popupwindows in a Visual Basic application. If the user places the cursor on acontrol and presses the F1 key, the context-sensitive text appears in asmall box.

NOTE: This article assumes that the reader has already prepared an HTMLHelp project file with the HTML Help Workshop and is ready to add context-sensitive text popup windows to it.

Step-by-Step Procedures

  1. Using a text editor, such as Word or Notepad, create a text topic file (.txt) that contains the text for the popup windows. Following is an example of how the statements should look in the text file:
          .topic 1      This is a text popup window for topic 1.      .topic 2      This is a text popup window for topic 2.      .topic 3      This is a text popup window for topic 3.						
    For each topic, the ".topic" is required, followed by a space and a numeric constant or number. The line immediately following must contain the text that you want to appear in the popup window.

    The text file could also appear as follows:
          .topic IDH_MYTOPIC1      This is a text popup window for topic 1.      .topic IDH_MYTOPIC2      This is a text popup window for topic 2.      .topic IDH_MYTOPIC3      This is a text popup window for topic 3.						
    In this example, you need to define the constants IDH_MYTOPIC1, IDH_MYTOPIC2, IDH_MYTOPIC3 in the [MAP] section of the help project file as follows:
          [MAP]      #define IDH_MYTOPIC1 1      #define IDH_MYTOPIC2 2      #define IDH_MYTOPIC3 3						
    There is additional information about creating the text topic file in the HTML Help Workshop Help under the topic "To create a context-sensitive help topic file".
  2. Include the topic text file in the [FILES] section and in the [TEXT POPUPS] section of the Help Project file. Following is an example where "cpopups.txt" is the name of the topic text file:
          [FILES]      topic1.htm      topic.htm      cpopups.txt      [TEXT POPUPS]      #include cpopups.txt						
    NOTE: Use a text editor to add the [TEXT POPUPS] and the #include statement.
  3. The following example shows the definitions required in your Visual Basic application. You should include these definitions in a module file in your project:
          Public Const HH_TP_HELP_WM_HELP = &H11      Declare Function HtmlHelpByRefArg Lib "hhctrl.ocx" Alias "HtmlHelpA"      (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As      Long, ByRef dwData As Any) As Long      Type HH_IDPAIR        dwControlId As Long        dwTopicId As Long      End Type      'This array should contain the number of controls that have      'context-sensitive help, plus one more for a zero-terminating      'pair.      Public ids(4) As HH_IDPAIR      Declare Function GetDlgCtrlID Lib "user32" (ByVal hWnd As Long) As      Long      Public Const g_sHTMLHelpFile As String =       "myhelpfile.chm::/cpopups.txt"						
    NOTE: This example assumes the .chm file is in the same directory as the Visual Basic application because no path is specified.
  4. Set the KeyPreview property of the Form to true.
  5. For each control that has a text popup window, set the values in the ids array. The first item should be the control id, which you can obtain by using the GetDlgCtrlID routine. The second item should be the topic id that appears in the topic text file. The following is an example of how to fill the array in the Form_Load routine:
          Private Sub Form_Load()       ids(0).dwControlId = GetDlgCtrlID(Me.MyButton.hWnd)       ids(0).dwTopicId = 1       ids(1).dwControlId = GetDlgCtrlID(Me.MyText.hWnd)       ids(1).dwTopicId = 2       ids(2).dwControlId = GetDlgCtrlID(Me.MyList.hWnd)       ids(2).dwTopicId = 3       ids(3).dwControlId = 0       ids(3).dwTopicId = 0      End Sub						
    NOTE: The last pair in the array must contain zeros (0).
  6. Intercept the KeyUp method of the Form to capture the F1 key press. For example:
          Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)       If KeyCode = vbKeyF1 Then            iRetCode = HtmlHelpByRefArg(Me.ActiveControl.hWnd,_                  g_sHTMLHelpFile, HH_TP_HELP_WM_HELP, ids(0))      End If      End Sub						
  7. Run your Visual Basic application. Select a control on the form and press the F1 key.
RESULT: The appropriate text popup window should appear on the screen.
"Official Microsoft HTML Help Authoring Kit", Steve Wexler, MicrosoftPress, 1998

The HTML Help Web site:

Article ID: 192118 - Last Review: 12/05/2015 09:13:02 - Revision: 2.2

Microsoft HTML Help 1.3, Microsoft HTML Help 1.1, Microsoft Visual Basic 5.0 Learning Edition, Microsoft Visual Basic 5.0 Professional Edition, Microsoft Visual Basic 5.0 Enterprise Edition

  • kbnosurvey kbarchive kbapi kbhowto KB192118