Class: WinHelp in Category Windows : Help Files from Total Visual SourceBook

Working with Windows Help (*.HLP) files in VB6 and VBA with 32 and 64-bit Windows API calls.

Code is included for opening, searching and closing help files. You can also open "Help on Help", contents pages, the help index, and run macros stored in help files. HLP format help files have been replaced by the more secure CHM help file format. Your Windows settings may prevent the ability to open an HLP file. Many of the Office and Visual Basic products provide tools for searching and displaying help files, but the VBA/VB6 solution is based on the use of the Common Dialog control. If your application is already using the Common Dialog control, it makes sense to use the Help facilities that VB offers. However, if you aren't using this control, and you need to implement support for Windows Help, this class is a better solution. Its size is obviously much smaller than the Common Dialog control, and its operation is very simple.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the CWinHelp class.
HelpFile Property Get the path/name of the currently set help file.
CloseFile Method Mark the current help file as closed.
Note: Windows Help is both a shared resource and a stand alone program, you cannot programmatically close a help file using the WinHelp API call. Instead, use this function to notify Windows Help that you are done with the help file. This releases the lock on the help file and allows your application to exit cleanly.
HelpOnHelp Method Open the Help on Help page. This method has the same effect as opening the WinHelp.hlp file, offering help on using the Windows Help engine.
OpenContentsTab Method Open the Contents tab of the current help file.
OpenContext Method Open the specified Help context in the current help file. This method opens a specific help topic by specifying the topic's unique Help Context ID numeric value. When you generate a help file, most tools generate a Map file that lists all the generated context ids. Use these values with this method to have your application display context-sensitive help.
OpenDefaultPage Method Open the default page of the current help file.
OpenFindTab Method Open the Find tab of the current help file.
OpenIndexTab Method Open the current help file with the Index tab active.
OpenIndexTabWithSearch Method Open the specified help file to the Index tab and supplies the specified search string as the Help search string.
RunMacro Method Runs the specified macro in the current help file. A help file macro is a sequence of commands embedded in the help file to perform extended operations.
' Example of the CWinHelp module
' To use this example:
' 1. Create a new form.
' 2. Create a command button called cmdHelp
' 3. Paste the entire contents of this module into the new form's module.

Private Sub cmdHelp_Click()
  Dim clsHelp As CWinHelp
  Dim lngContextID As Long

  ' Create a new instance of the class
  Set clsHelp = New CWinHelp

  ' Point to the help file
  clsHelp.HelpFile = "SAMPLE.HLP"

  ' Use the OpenContext method to display the topic associated with Help Context ID #1
  lngContextID = 1
  clsHelp.OpenContext lngContextID

  ' Display the help file for using Help.

  ' Open the help file to the default page.

  ' Open the help file with the Contents page active

  ' Open the help file with the Index tab active

  ' Open the help file with the Index tab active, and puts the supplies the word "Buttons" as the search phrase.
  clsHelp.OpenIndexTabWithSearch "Buttons"

  ' Finally, open the help file with the Find tab active.

  ' Run the macro called MyTest. Uncomment this line after supplying a valid macro name
  ' clsHelp.RunMacro "MyTest()"

  ' Mark the help file as closed.

  Set clsHelp = Nothing

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

View all FMS products for Microsoft Access All Our Microsoft Access Products


Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info




Free Product Catalog from FMS