Previous Page TOC Next Page



- 26 -
Creating Help Files for Database Applications


A purchaser of a commercial Windows application would undoubtedly return the product for a refund if a comprehensive online help system were not included. Users have come to expect context-sensitive help systems in all Windows applications, including shareware products. Context sensitivity means that the help system displays a window containing the topic that closely corresponds to what the user presently is attempting to accomplish with the application.

The help systems of mainstream Windows 95 applications use most, if not all, of the new features of Windows 95's 32-bit Winhlp32.exe; Winhlp32.exe eliminates the necessity of help authors being programmers too. (You can, however, write macros and Windows DLLs to create programmable help systems.) The version of Winhlp32.exe that accompanies Windows 95 and Windows NT 3.51+ provides a number of features that weren't available in the Windows 3.1+ version, such as Contents, Index, and Find tabs. This book covers only the Windows 95 and Windows NT 3.51+ versions of Winhlp32.exe and refers to Windows 95 and Windows NT .hlp files as WinHlp32 files that are used by the WinHlp32 engine.

Window's WinHlp32 engine enables you to create a single .hlp file that provides built-in instructions that Winhlp32.exe uses to display the appropriate topic information in a window with a predefined appearance and set of controls. One of the principal advantages of the WinHlp32 system is that the usage of Windows help features is quite inconsistent across the broad spectrum of Windows 3.1+ applications. If you follow the few simple help-file design guidelines presented in this chapter, the help files you create for your Visual Basic 4.0 database applications will perform identically to their larger kin, such as Winword.hlp (956KB for Word 7.0), Mainxl.hlp (1.3MB for Excel 7.0), and the other mega-.hlp files for mainstream 32-bit Windows applications.

This chapter briefly describes the new capabilities of the 32-bit Windows help system and how your Visual Basic 4.0 database applications can take advantage of the WinHlp32 system. Next, the chapter discusses how to organize your WinHlp32 system with context strings, context IDs, hypertext mapping, and other features that provide context-sensitivity, hypertext links, and browse mode sequences. The chapter concludes with a discussion of a commercial help-authoring tool that can aid you in creating WinHlp32 files and a discussion of how you can call the 32-bit WinHelp API function of User32.exe from Visual Basic code.

Reviewing the New Features of WinHlp32


WinHlp32 is backwardly-compatible with existing 16-bit WinHelp .hlp files, but does not extend the new features of WinHlp32 to Windows 3.1+ help files. Following is a list of the principal differences between Windows 3.1+'s WinHelp engine and WinHlp32:

Figure 26.1. The Contents page of the Visual Basic 4.0 help file, Vb.hlp.

Figure 26.2. A typical two-level index entry with the Topics Found dialog open.

Figure 26.3. The result of a full-text search on "ole server."

Figure 26.4. The Windows 95 Help Workshop displaying a help project file (Nwind.hpj).



32-bit Hcw.exe and its associated help files and DLL are included with the Professional and Enterprise editions of Visual Basic 4.0. These files are not installed in your \Vb4\hc folder by the Setup application. Setup only installs HC.EXE and related 16-bit WinHelp files. To install Hcw.exe, copy all of the files in the \Tools\Hcw folder of the CD-ROM to your \VB4\hc or a folder of your choice, then create a desktop shortcut or StartMenu choice that points to Hcw.exe.


Understanding How Visual Basic 4.0 and WinHlp32 Interact


Visual Basic 4.0 has features that enable you to assign individual help windows to forms and controls to create context-sensitive help. The interface between your Visual Basic application and your WinHlp32 .hlp file(s) comprises the following two basic elements:

The sections that follow describe how you create WinHlp32 files and how you assign context IDs to topics to create context-sensitive help.

Creating Rich Text Format Files for Help Systems


A WinHlp32 .hlp file is a compiled version of a word processing document file saved in Microsoft rich text format (.rtf). Rich text format is a page description language used to exchange formatted text between document processing applications. You use .rtf files, as an example, to transfer Microsoft Word from the Windows version to the Macintosh version. Most Windows word processing applications are capable of saving documents as .rtf files. Rich text format is similar in concept to Adobe's PostScript page description language, but .rtf is not used to print documents. Figure 26.5 shows part of the .rtf version of this paragraph, created by Word 7.0, displayed in Notepad's window.

The .rtf files that you create include a header that describes the page format, fonts, and styles in use. PostScript files contain a header that serves a similar purpose. An escape character (\) precedes page- and character-formatting data in .rtf files, and French braces (a.k.a. curly braces, {}) enclose groups of formatting data and text to which the formatting applies. Most of the header information in Word .rtf files is derived from the template (.dot file) in use when you write the document. Only a small part of the .rtf file header appears in Figure 26.5; the first sentence of the preceding paragraph is highlighted to identify the point where the paragraph starts.

Figure 26.5. Part of the .rtf version of a Word 7.0 document.

Adding Instructions to the WinHlp32 Engine


Instructions to the WinHlp32 engine are embedded in the .rtf file in the form of footnotes designated by footnote symbols, such as $ and #, rather than by conventional footnote numbers. Topic titles are designated by $ footnotes, and the context strings that uniquely identify a topic to the WinHlp32 engine use the # symbol. A topic is a help window that is devoted to a single subject; topics are separated from one another in your word processing document by hard page breaks (usually created with the Ctrl+Enter key combination). Figure 26.6 shows part of a simple help topic from the Nwind sample help file included on the accompanying CD-ROM.



All of the files required to create the Nwind.hlp Windows 95 help file with Hcw.exe are located in the \Ddg_vb4\32_bit\Chaptr26 folder of the accompanying CD-ROM.

Figure 26.6. The Contents topic of the Word 7.0 Nwind.doc file for the sample Nwind help project.

In Figure 26.6, Contents is the topic title and IDH_CONTENTS is the help context string for the topic. Hot spots are individual words, blocks of text, or images (.bmp or .wmf files) that are formatted with the double-underline or strikethrough attribute and are followed by a help context string formatted as hidden text. When you click a hot spot, WinHlp32 jumps to the topic identified by the context string that follows the hot spot text. Figure 26.7 shows the Help Topics Contents page of Nwind.hlp.

Figure 26.7. The Contents page of the Nwind.hlp sample help file.

Including Graphic Objects in Your WinHlp32 File


You can embed or link graphic objects contained in bitmap (.bmp) or vector image (.wmf) files in your WinHlp32 files. The easiest method of adding bitmapped images to your help files is to embed the image in .bmp format in your .doc or .rtf file using Word. However, large bitmap files usually are handled more efficiently by linking the graphic file to the WinHlp32 file by reference to its filename. Figure 26.8 shows the Nwind.rtf file help topic for the File | Printmenu choice. The icon (a bitmap image captured from Word 7.0's toolbar) is embedded in the .rtf document by choosing Picture from Word 7.0's Insert menu to display the Insert Picture dialog and then double-clicking Undo.bmp in the Name list. The {bmc Printcdl.bmp} entry below the line of text causes the Printcdl.bmp bitmap file to be inserted at the position of the { character.

Figure 26.8. A help topic with an embedded bitmap icon.



The term link is used in this chapter to differentiate between embedding a graphics file in the .rtf file and creating a reference to a separate graphics file with {bm? filename.ext} entries in your .rtf file. The ? placeholder determines whether the graphic is placed as a character , at the left margin (l), or at the right margin (r). When you compile the help file with the WinHlp32 compiler, the graphic that you link is embedded in the .hlp file you create, unless you specify otherwise. (You do not need to supply the .bmp file along with your .hlp file.)

Figure 26.9 shows the Print topic with the embedded print icon bitmap and the bitmapped image of the Print dialog that is linked with the {bmc printcdl.bmp} reference.

Figure 26.9. An embedded bitmap of a toolbar button and a linked bitmap of a common print dialog in Nwind.hlp.

You can create hot spots in graphic images you link to your WinHlp32 file using the 16-bit Hotspot editor, SHED.EXE, which is included with the Professional and Enterprise editions of Visual Basic 4.0 and is installed in your \Vb4\hc folder. The Hotspot editor creates an .shg (system hypergraphic) file from .bmp, .dib (device-independent bitmap), or .wmf files. To add hot spots to a .bmp, a .dib, or a .wmf file, follow these steps:

  1. Launch SHED.EXE and choose Open from the Editor's File menu to display the File Open dialog, which is not a Windows common dialog.

  2. Select the directory and filename of the bitmap in the Directories and Files lists; then click OK to close the File Open dialog and display the image.

  3. Position the mouse pointer at the upper-left corner of the area that you want to make active as a hot spot. Click the left mouse button and drag the enclosing rectangle to define the hot spot area; then release the mouse button.

  4. With the frame for your hot spot selected (using the eight sizing handles), choose Attributes from the Edit window to display the Attributes dialog. Enter the context string corresponding to the topic for the hot spot item in the Context String text box. Select Pop-up to create a pop-up window or Jump to jump to a new topic. Accept the default value, Visible, in the Attribute combo box and the Hotspot Id text box. You can manipulate the position of the enclosing rectangle by changing the entries in the text boxes within the Bounding Box frame.

  5. Click OK to assign the attributes to the hot spot. Add additional hot spots with their associated context strings as needed by repeating steps 3 and 4.

  6. When you've completed the definitions of the hot spots you want, choose Save As from the File menu and save your file with the same name as the original bitmap, but with the .shg extension, indicating that the bitmap file is now a hypergraphic file. Next, close SHED.EXE.

  7. If you have referred to the bitmap in your .rtf file using the .bmp extension, change the file extension to .shg. (You also need to change the reference in the [Bitmaps] section of the project file, which is the subject of the next section.)

  8. Add new topics to your WinHlp32 file for the pop-up or conventional help window(s) that appear when you click the hot spot(s). Each topic has a context string that corresponds to the context string you added during the editing process. Figure 26.10 shows the typical entries that define the attributes of a hot spot. Figure 26.11 shows the entry for the pop-up window that opens when you click the hot spot on the bitmap of the Northwind Traders logo.

    Figure 26.10. Defining the boundaries and attributes of a hot spot in a hypergraphic (.shg) file.

    Figure 26.11. Pop-up help window topics for a hot spot of the Northwind Traders logo.

  9. After you compile your WinHlp32 .rtf file to a .hlp file, clicking a hot spot displays the pop-up window whose context string corresponds to the context string you assigned as the hotspot's attribute. (Compiling .rtf to .hlp files is the subject of the next section.) Figure 26.12 shows the pop-up window that appears when you click the area within the dashed lines surrounding the lighthouse. The dashed lines appear because Visible was selected as the attribute for the hot spot regions. (Normally you choose invisible so the dashed lines do not appear.)

Figure 26.12. The pop-up window that is displayed when you click the lighthouse hot spot.



One of the advantages of using SHED.EXE is that the Hotspot editor compresses the .bmp files. As an example, Nwind.bmp requires 24KB of storage, while Nwind.shg occupies only 11KB. Note also that you cannot add hot spots to bitmaps you embed in WinHlp32 .rtf files.


Compiling .rtf Files to Create WinHlp32 .hlp Files


Creating the final WinHlp32 .hlp file from your .rtf file and any graphics that are referenced in the .rtf file is a three-step process:

  1. Create a project file that provides information to the help compiler on the file(s) that constitute your help file and assigns a help context ID value to each help context string.

  2. Use Hcw.exe, the Windows 95 help compiler, to compile the .rtf and the other files you specify into the WinHlp32 .hlp file.

  3. Test your .hlp file to make sure it conforms to your expectations.

The three sections that follow describe the preceding steps.

Creating a Project File

Help project files, which usually are named AppName.hpj, are similar in concept to Visual Basic 4.0 project files and to C and C++ make files. The content of the project file for the Nwind.hlp sample help file, Nwind.hpj, appears in Listing 26.1.

Listing 26.1. Sections and entries in the Nwind.hpj help project file.




[OPTIONS]



HCW=0



ERRORLOG=.\NWIND.ERR



LCID=0x409 0x0 0x0 ;English (United States)



REPORT=No



CONTENTS=IDH_CONTENTS



TITLE=Northwind Traders Example Help File



BUILD=WINDOWS



HLP=.\Nwind.hlp



[FILES]



NWIND.RTF



[BUILDTAGS]



WINDOWS



[MAP]



IDH_Contents=10



IDH_Customers=230



IDH_Edit_Menu=120



IDH_Entering_Invoices=221



IDH_Entering_Orders=211



IDH_File_Menu=110



IDH_Invoices=220



IDH_Logging_Off=302



IDH_Logging_On=301



IDH_Menu_Commands=100



IDH_Networking=300



IDH_Orders=210



IDH_Print=117



IDH_Procedures=200



IDH_Undo=121



IDH_View_Menu=130



IDH_Workgroups=303



[CONFIG]



BrowseButtons()



CreateButton("Glossary_Btn","&Glossary",



   "JI(qchPath,`IDH_Glossary')")

Help project files are text files that are organized into sections and are similar in structure to Windows 3.1+ .INI files. Table 26.1 lists the most commonly used sections of a help project file, whether the section is required in the file, and a brief description of the purpose of the section. Keywords for entries in the options section also are described in Table 26.1.

Table 26.1. The primary sections of a help project (.HPJ) file.

Section of .HPJ File Section Required? Description
[OPTIONS] No (but usually present) Defines the options that control the WinHlp32 compilation process. Some of the more common option entries include the following:
[OPTIONS] Keywords

ROOT=d:\path Defines the path to your help source files.

CONTENTS=ContextString Sets the context string for the index topic with the Windows 3.1 Help compiler, HC31.EXE.

TITLE=AppName Help Sets the title for the WinHlp32 file, which appears in the help window's title bar.

ICON=IconFile.ico Sets the icon that is displayed when the help window is minimized.

COMPRESS=0|False Controls file compression. 0, or False, means do not compress files. 1, or True, compresses the file. Compressing .hlp files saves disk space at the expense of speed in displaying help windows (due to the time required to decompress the file).

WARNING=3 Determines what errors are reported. 0 through 3 control the level of error reporting: 0 = no error reports; 1 = most severe warnings; 2 = intermediate warning level; and 3 = report all warnings.

REPORT=1|ON Determines whether progress reports of the compilation are provided. 1, or ON, = report progress of compile; 0, or OFF, = no report.
[FILES] Yes Specifies the help source files included in the compilation.
[BUILD] No Specifies topics to include in or exclude from the compiled file.
[BUILDTAGS] No (Yes if [BUILD] specified) Names valid build tags, enabling the selection of topics to be compiled within a file.
[CONFIG] Only if DLL functions are called or buttons added Registers custom DLLs whose functions are called by WinHlp32 macros, including macros for adding buttons to help topic pages.
[BITMAPS] No Specifies bitmap or .wmf files used in the compilation and not embedded in your WinHlp32 document. This section is not required if you used the ROOT= entry in the section to specify the path to the referenced bitmap files.
[MAP] No (but usually present) Associates context strings with context ID numbers. You need a map section to use the ContextID property of Visual Basic forms and control objects.
[ALIAS] No Enables you to assign more than one context string to a subject.
[WINDOWS] No Describes the main WinHlp32 window and any secondary window types in the help file.
[BAGGAGE] No Names any additional data files that are to be incorporated within the WinHlp32 file.


You can write a simple help project file in NotePad, WordPad, or any other word processing application that outputs conventional ASCII test files. Commercial help-authoring tools, such as RoboHELP 95, automatically create the AppName.hpj project file for you. Using a help-authoring tool saves a substantial amount of time, especially when creating help files with a large number of help topics. Using RoboHELP 95 is described later in this chapter.


Using Hcw.exe to Compile your WinHlp32 .rtf File

Once you've written the AppName.rtf and AppName.hpj files for your Visual Basic 4.0 application, you use Hcw.exe (Help Workshop) to compile your help file and its associated graphic elements, if any, into AppName.hlp (the primary help file) and AppName.cnt (the contents file that creates the entries for the Contents page). The following steps describe the use of Hcw.exe to compile a WinHlp32 help file:

  1. Launch Hcw.exe, choose File | Open, and open your AppName.hpj file. Figure 26.13 shows Help Workshop displaying the Nwind.hpj file of preceding Listing 26.1.

    Figure 26.13. The first three sections of a simple WinHlp32 .hpj file displayed in the Microsoft Help Workshop.

  2. The buttons on the right of Help Workshop's window correspond to the sections of AppName.hpj. Clicking Options opens the Options tabbed dialog, which lets you enter required and optional project file data. Figure 26.14 illustrates addition of COPYRIGHT= and CITATION= entries in the OPTIONS section; the text you type appears in the help Version dialog and when pasting copied help text, respectively.

    Figure 26.14. Adding copyright and citation entries for the OPTIONS section of the .hpj file.

  3. Clicking the Map button opens the Map dialog for adding or editing entries that map context strings to numeric context ID values. Clicking the Add or Edit button of the Map dialog opens the Add Map Entry or Edit Map Entry dialog. (See Figure 26.15.)

    Figure 26.15. Adding a comment to the IDH_Contents context string in the Edit Map Entry dialog.

  4. After you've edited your help file as necessary, click the Save and Compile button to create your AppName.hlp file from the AppName.hpj and other WinHlp32 source files. The Help Workshop window closes during compilation and then reopens with the compilation report. Figure 26.16 shows the Compilation window with messages warning that two topics are missing from the [MAP] section of the project file.

    Figure 26.16. The report generated for the third compilation of the Nwind.hlp example help file.

  5. Click the Run WinHelp (?) button of the toolbar to open the View Help File dialog. Select a context string for a help topic in the Mapped Topic IDs list and select the A double-clicked file icon option button in the Open Help file as if it were frame. (See Figure 26.17.)

    Figure 26.17. Choosing display options in the View Help File dialog.

  6. Click the View Help button to display the help topic. The A double-clicked file icon option causes the help file's Help Topics window to appear with the Contents page selected.



To create help files for 16-bit Windows 3.1+ applications, you use HC.EXE with the name of the project file as its command line argument, as in HC [PATH\]APPNAME.HPJ, from the DOS prompt. Operation of HC.EXE during the compilation process is similar to that of Hcw.exe. Warning or error messages are written to the DOS window.


Using Help-Authoring Tools


Chapter 3, "Creating the Topic Files," in the Help Compiler Guide refers to various versions of Microsoft Word and other word processing applications that support .RTF as help "authoring tools." This is a questionable definition, because help-authoring tools usually are defined as commercial (including shareware) applications or Word for Windows templates that provide at least the features in the following list:

At the time this book was written, there was no Windows word processing application available that provided any of the features in the preceding list. No Visual Basic database application developer should be without a commercial help-authoring tool that includes at least the preceding features. The section that follows describes Blue Sky Software's RoboHELP 95, a retail help-authoring systems with a sophisticated feature set.

Using Blue Sky Software's RoboHELP 95


It's an uncommon practice to create Windows help files without the aid of a commercial or shareware help-authoring tool. There are a variety of help-authoring tools available for 16-bit Windows 3.1+ help, but relatively few applications for creating full-scale WinHlp32 help files. This section briefly describes one of the most popular professional help file authoring tools for Windows 95 and Windows NT 3.51+ applications—RoboHELP 95.

Blue Sky Software Corporation's RoboHELP 95 consists of several custom DLLs and help templates for Microsoft Word 7.0. Blue Sky Software includes Hcw.exe and SHED.EXE with RoboHELP, as well as an icon and bitmap editing application, PaintIt, a screen capture utility, and a 32-bit OLE control, Smthlp32.ocx, that you can use to add a stylized help button to 32-bit Visual Basic toolbars and forms. RoboHELP 95 also provides a set of tutorial files and a help file that explains how to create secondary help windows. RoboHELP comes with a well-written and thoroughly indexed 450-page manual.

RoboHELP 95 is designed primarily for authoring help files from scratch in Word 7.0, rather than from a pre-existing manual in the form of a .doc file. RoboHELP 95 includes a utility for importing an existing .doc file into a new RoboHELP .doc file, then changing the existing styles to conform to RoboHELP 95 style. When you launch RoboHELP 95 from the Start menu, you have the choice of creating a new project or opening an existing project. Figure 26.18 shows the Create New Help Project dialog with entries to create a test help project.

Figure 26.18. Entering the help project title and filename for a new WinHlp32 help file.

RoboHELP 95 provides a floating toolbox, similar in concept to Visual Basic's toolbox, that enables you to choose from one of 14 different actions. Figure 26.19 shows RoboHELP 95 displaying part of the Nwind.doc help source file inserted into the new help project document. RoboHELP's default font size is 8 points for Windows 95 help files.

Figure 26.19. RoboHELP 95's toolbox for choosing help-authoring functions.

When you click the Topic button of the toolbox to add a new topic to your help document, RoboHELP displays the Insert New Help Topic dialog shown in Figure 26.20. (Click the Advanced button to display the Context String, Browse Sequence, Build Tag, and Macro text boxes.) You enter the help topic title and the search keywords for the topic, if any. With the advanced options selected, you can choose your own context string to identify the topic.

Figure 26.20. RoboHELP's dialog for adding a topic to a help document.

To create a hot spot with a jump to another topic, you click the Jump button of the toolbox to display the Create New Jump Hotspot dialog shown in Figure 26.21. You can add a bitmapped graphic as the hot spot by clicking the Graphic button to display a choice of compatible graphics files (.bmp, .dib, and .wmf). Figure 26.22 shows the Shortcut.bmp file included with RoboHELP 95 in the Insert Graphics Object in Hotspot Text dialog. Figure 26.23 shows the new topic added to the Robo95.doc source file.

Figure 26.21. RoboHELP 95's Create Hypertext to Help Topic dialog.

Figure 26.22. Adding a bitmap graphic to the hot spot with RoboHELP's Insert Graphics Object in Hotspot Text dialog.

Figure 26.23. The new help topic added to the end of the inserted help document.

You need to create a contents file (AppName.cnt) before compiling your WinHlp32 project. Clicking the Add Contents toolbox button (the book icon with a ?) opens the Contents Tab Composer dialog. If you haven't previously created a contents file, click the Add All button to add all of the help topics shown in the Topics pane to the Content Tab Composer pane. Right-click topics that have subtopics to display the pop-up menu and choose Convert to Book to change the page icon to a book icon. Use the left and right arrow buttons to determine the level of the books in the hierarchy of the Contents page of the Help Topics dialog. (See Figure 26.24.)

Figure 26.24. Creating the help topic hierarchy for the Contents page of the Help Topics dialog.

To create the .hlp file from your help document, you choose Project | Make or click the Make Project button and then click OK to save changes to your .doc and .rtf files to display the Make Project tabbed dialog shown in Figure 26.25. Clicking the Check tab lets you run a diagnostic test on the .rtf file that RoboHELP creates from your .doc file. Click the Make button of the Make Project page to start the compilation process. If no errors are detected, RoboHELP displays the dialog shown in Figure 26.26 while Hcw.exe compiles your .hlp file. Click the Run button of the Make Help Project into Help File dialog to display the Help Topics dialog for the WinHlp32 help file. Figure 26.27 shows the window for the New Test Help Topic shown in preceding Figure 26.23.

Figure 26.25. RoboHELP 95's Make Project dialog.

Figure 26.26. The progress dialog that appears while RoboHELP runs Hcw.exe to compile your .hlp file.

Figure 26.27. The new topic window with a hot spot and jump button.

The project file, Robo95.hpj, created by RoboHELP for the Robo95.hlp file appears in Listing 26.2. (Most of the comments included by RoboHELP in the Robo95.hpj file have been deleted from Listing 26.2.) The [MAP] section of Robo95.hpj is empty because no help context ID values are assigned to the context strings.

Listing 26.2. The help project file created by RoboHELP for the Robo95.hlp file, less comments.




; Help Project File for ROBO95



[OPTIONS]



;BMROOT=C:\DDG_VB4\32_BIT\CHAPTR26



TITLE=RoboHELP 95 Test Project



BUILD=WINDOWS



NOTES=1



OLDKEYPHRASE=NO



OPTCDROM=0



REPORT=YES



COMPRESS=12



ERRORLOG=C:\DDG_VB4\32_BIT\CHAPTR26\ROBO95.ERR



[BUILDTAGS]



WINDOWS



CONFIG]



[FILES]



ROBO95.RTF



[ALIAS]



[MAP]



[BITMAPS]



[WINDOWS]



;Gloss="Glossary",(100,100,350,350),0,(255,255,255),



   (255,255,255)main=,,29188,,



(w95sec)=,,20740,(r14745599),(r14745599),f2



[BAGGAGE]

Calling the WinHlp32() Function with Visual Basic Code


Designating the master help file for your project and assigning property values to form and control objects provides all the WinHlp32 capabilities you need for most Visual Basic applications. However, if you use Visual Basic procedures that change how control objects behave, you may need to set the HelpContextID values in Visual Basic procedures.

To control the action of the WinHlp32 engine with Visual Basic code, you call the WinHelpA (ANSI) function when you need to change a help filename or context ID value. WinHelpA is aliased to WinHelp in the function declaration, discussed in the next section. The syntax of the 32-bit WinHelp function call, which is the sole help function contained in the User32.exe DLL, is as follows:




lngHelpOK = WinHelp(hWnd, szHelpFile, wCommand, dwData)

In the preceding syntax, lngHelpOK is an Long variable used to receive the return value of the WinHelp function. The arguments of the WinHelp function are explained in the following sections.

Declaring the WinHelp Function Prototype


You declare the WinHelp function in the Declarations section of a module with the following statement:




Declare Function WinHelp Lib "user32" Alias "WinHelpA" _



  (ByVal hWnd As Long, _



   ByVal lpHelpFile As String, _



   ByVal wCommand As Long, _



   ByVal dwData As Long) As Long


As with other 32-bit Windows API function calls that have arguments of the String data type, you call the ANSI version (WinHelpA) rather than the Unicode version (WinHelp) of the function. Aliasing WinHelpA to WinHelp, although designed for backward compatibility with 16-bit Windows API calls, is a common practice when writing 32-bit code. The 32-bit version of WinHelpA uses the Long data type for Windows handles (hWnd), the help command (wCommand), and the return value. For backward compatibility, Windows 95 and Windows NT also provide 16-bit USER.EXE DLL, which includes the 16-bit WinHelp function.

The following list explains the statement's components for 32-bit Visual Basic 4.0 applications:


Table 26.2. WinHlp32 wCommand constant values and corresponding actions.

wCommand Constant Value Description
HELP_CONTEXT 1 Causes a specific help topic, identified by a Long integer specified as the dwData argument, to be displayed.
HELP_QUIT 2 Notifies WinHlp32 that the specified help file is no longer in use and can be closed. The dwData argument is ignored.
HELP_INDEX 3 Displays the index of the specified WinHlp32 file, as designated by the author. The dwData argument is ignored.
HELP_HELPONHELP 4 Displays help for using the WinHlp32 application itself. The dwData argument is ignored.
HELP_SETINDEX 5 Sets the context number specified by the dwData argument, a Long integer, as the current index for the specified WinHlp32 file.
HELP_KEY 257 Displays the first corresponding topic found in a search for the keyword specified by the dwData argument—in this case, as a String variable.
HELP_MULTIKEY 513 Displays help for a keyword found in an alternate keyword table. The dwData argument is a data structure (user-defined data type) containing the size of the string, the letter of the alternate table, and the keyword string.


32-bit WinHelp adds HELP_CONTEXTMENU, HELP_FINDER, HELP_SET_POPUT_POSITION, HELP_TCARD, and HELP_WM_HELP constants to the preceding list. As is the case with HELP_KEY and HELP_MULTIKEY, it's seldom necessary to use these new constant values.

Table 26.2 describes how the data type of the argument changes with the value of dwData. The dwData argument may be a Long integer (the most common data type), a String variable, or a user-defined data type. If you need to use the HELP_KEY or HELP_MULTIKEY values, dwData is declared As Any and is passed by reference, not by value. When you want dwData to be ignored by WinHelp, you should set dwData to &H0 (null, rather than decimal 0) in your Visual Basic WinHelp function call.

You don't need to add the constants listed in Table 26.2 to the Declarations section of your module if you want to substitute the Long integer values shown in Table 26.2 as the dwData argument when you use the WinHelp function. You must, however, declare the MKH (multikey help) structure in your global module, declare a record variable, and assign values to its fields in your code if you plan to use more than one help key in your application. It's a good programming practice to make the name of your help file a Public variable.

Using the WinHelp API Function in Your Visual Basic Code


Assign the name of your help file to a Public variable, such as strHelpFile, and default wCommand and dwData values to lngCommand and lngHelpCtx in your Main subprocedure or in the Form_Load event-handler of the start-up form. These variables are made Public so that they retain the last value set to all modules contained in your application. You set lngHelpCtx to the value of the help context ID of the topic you want to display when the user requests help at a particular point in your code. The following is the code that appears in Sub Main or in the Form_Load event-handler:




'Assign initial values to help variables



strHelpFile = "FileName.hlp"



lngCommand = [HELP_CONTEXT|&H1]



lngHelpCtx = &H1

To display a help window with a minimum of typing, add two subprocedures, FormHelp and ControlHelp, to a module. The code for the two subprocedures is as follows:




Sub FormHelp



   'Purpose: Display a help window for a form



   lngHelpOK = WinHelp(Screen.ActiveForm.hWnd, _



      strHelpFile, lngCommand, lngHelpCtx)



End Sub



Sub ControlHelp



   'Purpose: Display a help window for a control



   lngHelpOK = WinHelp(Screen.ActiveControl.hWnd, _



      strHelpFile, lngCommand, lngHelpCtx)



End Sub


If you specify dwData As Any, lngHelpCtx must be passed by value to dwData; but in this case the function prototype declaration does not include ByVal, so you must include the ByVal prefix with the argument when you call the function. lngHelpCtx is set to &H0 when dwData is ignored by WinHelp.


Summary


Online help is a critical component of all but the most rudimentary database applications. This statement applies not only to Visual Basic 4.0 Windows database applications, but also to database front-ends you create in any language. This chapter was not meant to be a substitute for the Help Compiler Guide, nor did it provide the scope of books that are devoted to authoring WinHlp32 files. If the examples of using the RoboHELP 95 commercial help-authoring tool that was described in this chapter accomplished their purpose, you'll acquire such a help authoring tool to accelerate the development of online WinHlp32 for your Visual Basic 4.0 database applications.

The next chapter, the last in this book, describes how you organize the Setup application for your Visual Basic 4.0 database front-ends and how to manage the distribution of your applications on diskettes.

Previous Page Page Top TOC Next Page