Visual Basic > Files Directories Drives
Displaying HTML help files
Displaying HTML help files The following code demonstrates a technique for showing HTML help files. Option Explicit Private Declare Function HTMLHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" (ByVal hWnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long Private Declare Function GetActiveWindow Lib "user32" () As Long Private Const HH_DISPLAY_TOC = &H1, HH_DISPLAY_INDEX = &H2, HH_DISPLAY_SEARCH = &H3 'Purpose : Shows a windows help file (chm file) 'Inputs : sHelpFile The path to the help file. ' [lDisplayType] The section of the help file to display. ' Can be any of the HH_DISPLAY_ constants. ' [lContextID] The context ID of the topic to display. 'Outputs : Returns the handle of the Help file window on success, else returns zero. 'Notes : GetActiveWindow can be replaced by Me.Hwnd in VB Function HTMLHelpShow(sHelpFile As String, Optional lDisplayType As Long = HH_DISPLAY_TOC, Optional lContextID As Long) As Long HTMLHelpShow = HTMLHelp(GetActiveWindow, sHelpFile, lDisplayType, lContextID) End Function 'Demonstration code Sub Test() 'Show Helpfile Debug.Print HTMLHelpShow("C:\myhelpfile.chm") End Sub 'VB Show specific help context Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyF1 Then Debug.Print HTMLHelpShow("C:\myhelpfile.chm", , Me.ActiveControl.HelpContextID) End If End Sub 'VBA Show specific help context Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = vbKeyF1 Then Debug.Print HTMLHelpShow("C:\myhelpfile.chm", , Me.ActiveControl.HelpContextID) End If End Sub
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows