This article was previously published under Q192118
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article 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.
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:
NOTE: Use a text editor to add the [TEXT POPUPS] and the #include statement.
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.
Set the KeyPreview property of the Form to true.
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).
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
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