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 />

New Commands<br />

Figure 16-3. “Help Topics” property sheet<br />

First, after the standard project is generated, four new commands are added to the application. These<br />

commands are implemented in both the mainframe menu and the tool bar, and their IDs are<br />

ID_HELPTEST_TESTA, ID_HELPTEST_TESTB, ID_HELPTEST_TESTC and ID_HELPTEST_TESTD respectively. In<br />

IDR_MAINFRAME menu, the new commands are Help Test | Test A, Help Test | Test B, Help Test | Test C,<br />

and Help Test | Test D. In the IDR_MAINFRAME tool bar, we also have four buttons corresponding to the four<br />

command IDs. The message handlers of these commands are all blank, because we just want to<br />

demonstrate how to implement context sensitive help for them.<br />

Editing “AfxCore.rtf”<br />

We must add four items to the help file in order to link a command to the help. In order to do this, we<br />

must modify file “AfxCore.rtf”. The rich text format file can be edited by a word processor like Microsoft<br />

Word (WordPad is not powerful enough for this purpose, because it does not support footnote editing).<br />

Within this file, each help item is managed as a footnote. If we want to add a new help item, we just need to<br />

add a new footnote.<br />

To show how to add a footnote to the “.rtf” file, lets assume that we want to add a footnote for<br />

ID_HELPTEST_TESTA command.<br />

Each footnote must be associated with a tag, so that it can be referenced from inside or outside the file.<br />

In Microsoft Word, we can either add number-based tags or user-defined tags. To make the tags<br />

meaningful, usually we define tags by ourselves. The tags can be any string, usually they will have some<br />

relationship with the command IDs implemented in the application. For example, we can use “help_test_A”<br />

as the tag for the footnote that will be used to implement help for the command whose ID is<br />

ID_HELPTEST_TESTA.<br />

To add a new tag within Microsoft Word, first we need to move the cursor to the bottom of the file,<br />

then execute Insert | Break… command. From the popped up dialog box, we need to check the radio<br />

button labeled “Page Break”. If we click “OK” button, a new page will be added to the file (Generally each<br />

footnote needs to use one page, so we need to add page break whenever a new footnote is added). Now<br />

execute Insert | Footnote command, and check the radio button labeled “Footnote” from the popped up<br />

dialog box (in “Insert” section). Then, check radio button labeled “Custom Mark” (in “Numbering”<br />

section) and input a ‘#’ into the edit box beside it (Figure 16-4). Finally, click “OK” button. Now the client<br />

window of Word will split into two panes, the lower of which will show all footnote tags. The caret will be<br />

placed right after the ‘#’ sign waiting for us to type in the footnote tag. We can type “help_test_A”, then<br />

click on the upper pane. Then we can input any help description for command ID_HELPTEST_TESTA.<br />

483

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

Saved successfully!

Ooh no, something went wrong!