11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 16. Context Sensitive Help<br />

Button used to<br />

implement context<br />

sensitive help, whose<br />

ID is<br />

ID_CONTEXT_HELP<br />

Figure 16-2. Button used to implement context sensitive help<br />

By default, contents of help are stored in a rich text format file generated by the Application Wizard:<br />

“AfxCore.rtf”. We can find many footnotes within this file, each footnote corresponds to one help page. To<br />

implement the context sensitive help for a custom menu command, we need to add a new footnote to file<br />

“AfxCore.rtf”, and link it to the command.<br />

If the context sensitive help is enabled within the Application Wizard in step 4 (see Figure 1-1), the<br />

help project will be generated automatically. All the files used to build the help will be contained in a “hlp”<br />

directory under the project directory. For example, if we use the Application Wizard to generate an SDI<br />

application named “Help”, the help project will be generated under “Help\hlp\” directory. There will be a<br />

batch file “Makehelp.bat” under the “Help” directory. Also, there are some other important files under<br />

“Help\hlp” directory that are used to build the help. The following table lists the usages of these files:<br />

File name<br />

MakeHelp.bat<br />

*.hpj<br />

*.cnt<br />

*.hm<br />

AfxCore.rtf<br />

AfxPrint.rtf<br />

Description<br />

Batch file, make the help<br />

Help project file<br />

Help contents file<br />

Help ID mapping file<br />

Rich text format file, which need to be updated by the user to support new commands<br />

Rich text format file, which will be used to generate *.hlp file for print commands<br />

The help is compiled by a utility named “Microsoft Help Workshop”. The executable file “Hcw.exe”<br />

can be found under Visual C directory “~DevStudio\Vc\Bin\”. This utility can compile “*.hpj” file to<br />

generate a target help file.<br />

By double clicking on the “*.hpj” file or “*.cnt” file (In “Explorer”, they are described as “Help<br />

project file” and “Help contents file” respectively), we can compile the help project in the help workshop<br />

environment. Also, when we compile the application in Developer Studio, the help project will also be<br />

compiled. The help project file (“.hpj) is similar to a make file when we execute C compilers, it contains<br />

information about how to generate the target help file. The help contents file (“.cnt”) contains the<br />

information of “help topics”. If we execute Help | Help Topics command from the application, the help<br />

contents will be displayed in a “Help Topics” property sheet (Figure 16-3). All the descriptions about the<br />

commands and the application are included in “AfxCore.rtf” and “AfxPrint.rtf” files, we must edit them in<br />

order to add custom help descriptions.<br />

Sample<br />

Because the default help project already has many help items, without the knowledge of the help<br />

project, it is difficult for a programmer to add items for the newly added commands. Sample 16.1\Help is a<br />

standard SDI application generated by Application Wizard, which demonstrates how to add new help items<br />

and link them to the application commands to support context sensitive help.<br />

482

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!