VB6: HTML Help (CHM) from a button -TOC - index - search

The most important ways to open help are F1 and a Help button that open content sensitive help. You can add additional ways to call the Help file:

Download
You can import the required module from the VB6 demo application which you can download from here: vb6_activating_help.zip

Adding code to implement additional Help features

  1. Import the following modules and classes in your application
  2. Open the form you want to add the help button to in Design mode
  3. Add a [Help] button to a form
  4. Set the button property name to 'cmdHelp' (or something like that - give it meaningul name)
  5. Right-click on the newly created button
  6. Select 'Build Event'
  7. Select Code Builder and click OK
  8. The VB editor opens with Private Sub 'cmdHelp_Click() ... End Sub inserted
  9. Insert code so that the result looks like in the sections below, depending on required behavior. 

Open Help on Table Of Contents tab

Private Sub cmdHelpTOC_Click()
    HTMLHelp.OpenTOC HelpFile() , Me .hwnd
End Sub

Open Help on Index tab

Private Sub  cmdIndex_Click()
    HTMLHelp.OpenIndex  HelpFile() , Me .hwnd
End Sub

Open Help on Search tab

Private Sub cmdSearch_Click()
    HTMLHelp.OpenSearch  HelpFile() , Me .hwnd
End Sub

Open Help using a Topic page url and optionally bookmark

Private Sub cmdBookmark_Click()
Dim strHtmlFileName  As String
Dim strHtmlFileBookmark As String
Dim strBookmark  As String
    strHtmlFileName = "frmCustomers_CustomHelp.htm"
    strHtmlFileBookmark = "frmCustomers_CustomHelp_Phone"
    
    strBookmark = strHtmlFileName
     If Len (strHtmlFileBookmark) > 0  Then
       strBookmark = strBookmark & "#" & strHtmlFileBookmark
     End If
    HTMLHelp.OpenTopic strBookmark,  HelpFile()
End Sub 

Open Help using Help Context Id

Private Sub cmdContextId_Click()
Dim lHelpContextId As Long
    lHelpContextId = Screen.PreviousControl.HelpContextId
    If lHelpContextId = 0 Then
        lHelpContextId = me.HelpContextId
    End If
    HTMLHelp.OpenContext lHelpContextId, HelpFile()
End Sub
VB6: starting help from code