Microsoft KB Archive/315988

= HOW TO: Use HTML Help from Visual Basic 6.0 =

Article ID: 315988

Article Last Modified on 11/25/2002

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q315988





IN THIS TASK
SUMMARY
 * Requirements
 * Create a Hypertext Markup Language (HTML) Help File
 * Validate the Help File
 * Create a Visual Basic Application that Uses the Help File
 * Verify That It Works

REFERENCES



SUMMARY
This article describes how to call HTML Help from a Visual Basic 6.0 application.

The principal entry point for HTMLHelp operations in Microsoft Visual Basic is the HTMLHelp function. This application programming interface (API) function is declared as follows: Private Declare Function HTMLHelp Lib &quot;HHCtrl.ocx&quot; Alias &quot;HTMLHelpA&quot; _ (ByVal hWndCaller As Long, _    ByVal pszFile As String, _     ByVal uCommand As Long, _     dwData As Any) As Long The first parameter represents a parent window for your application. The second parameter is the name of the compiled (.chm) file that contains the help data. The third parameter is a value that represents an HTMLHelp command. The fourth parameter is additional data, the value and format of which depends on the HTMLHelp command.

NOTE: The fourth parameter is declared &quot;As Any&quot; (without quotation marks). The actual type of data that must be supplied depends on the HTMLHelp command that is being used. Be careful to pass the appropriate data values for whichever HTMLHelp command you are using. The sample program in this article demonstrates how to use some of these HTMLHelp commands.

back to the top

Requirements
The following items describe the recommended hardware, software, network infrastructure, skills and knowledge and service packs you will need.
 * HTML Help 1.3

Prior Knowledge required:
 * You should have knowledge of Visual Basic development.

back to the top

Create an HTML Help File
 Click Start, point to Programs, and then click HTML Help Workshop two times to start HTML Help Workshop. On the File menu, click New. In the New dialog box, click Project, and then click OK. The New Project wizard starts. Follow these steps in the New Project Wizard:  In the first dialog box, press Next. In the Destination dialog box, enter the folder and file name for the help project, and then click Next. The following folder and file name are examples:

C:\Documents and Settings\ \My Documents\HHDemo\HHDemo.hhp

</li> In the Existing Files dialog box, press Next.</li> Click Finish to create a blank project.</li></ol> </li> On the File menu, click New.</li> In the New dialog box, click HTML File, type Default for the title, click OK, type Default between the <BODY> and </BODY> tags, and then save this file as Default.htm.</li> On the File menu, click New.</li> In the New dialog box, click HTML File, type Sample Topic for the title, click OK, type Sample Topic between the <BODY> and </BODY> tags, and then save this file as Sample.htm.</li> On the left toolbar in the HTML Help Workshop window, click Add/Remove topic files.</li> Click Add, browse for both the Default.htm file and the Sample.htm file in the file selection dialog box, click Open, and then click OK. The two files are now listed in the Files section at the left of the HTML Help Workshop window.</li>  Open a text editor, such as Notepad, and then type the following context IDs: Save the file as Map.h in the same folder as the other HTMLHelp project files that you have created. </li> On the left toolbar in the HTML Help Workshop window HTML Help Workshop, click HtmlHelp API information, click Header File, type the file name Map.h, and then click OK two times.</li> On the File menu, click Save All Files.</li> On the File menu, click Compile.</li> In the Create a compiled file dialog box, click Compile. This creates a compiled HTML help file named HHDemo.chm.</li></ol>
 * 1) define DEFAULT 100
 * 2) define SAMPLE 101

back to the top

Validate the Help File

 * 1) Open the HHDemo.chm file in Microsoft Windows Explorer.
 * 2) When the HTMLHelp window opens, one of the topic pages appears.

back to the top

Create a Visual Basic Application that Uses the Help File
<ol> Start a new Visual Basic 6.0 Standard EXE Project.</li> Add two Command buttons to Form1. The buttons have the default names Command1 and Command2.</li> <li> Add the following code to the General Declarations section of Form1: Option Explicit

Private Declare Function HtmlHelp Lib &quot;HHCtrl.ocx&quot; Alias &quot;HtmlHelpA&quot; _ (ByVal hWndCaller As Long, _    ByVal pszFile As String, _     ByVal uCommand As Long, _     dwData As Any) As Long

Const HH_DISPLAY_TOPIC As Long = 0 Const HH_HELP_CONTEXT As Long = &HF

Private Sub Form_Load ChDir App.Path End Sub

Private Sub Command1_Click HtmlHelp hWnd, &quot;HHDemo.chm&quot;, HH_DISPLAY_TOPIC, ByVal &quot;Sample.htm&quot; End Sub

Private Sub Command2_Click HtmlHelp hWnd, &quot;HHDemo.chm&quot;, HH_HELP_CONTEXT, ByVal 100& End Sub </li> <li>Save the files for this project in the same folder as the sample HTMLHelp file.</li></ol>

back to the top

Verify That It Works

 * 1) Build and run the application.
 * 2) Click Command1. The HTMLHelp program displays the topic Sample.htm file. This technique uses a search by topic name.
 * 3) Click Command2. The HTMLHelp program displays the topic Default.htm file. This technique uses a search by context ID.

back to the top