11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 16. Context Sensitive Help<br />

ID Naming Rules<br />

Button Used to<br />

Enter Help Mode<br />

Figure 16-9. Dialog box supporting context sensitive help<br />

Adding context sensitive help for common controls is more complicated than that of menu commands.<br />

First we must add footnotes for each common control contained in the dialog box, then we need to do the<br />

ID mappings.<br />

By default, <strong>MFC</strong> will generate help IDs for the commands or controls whose resource IDs start from<br />

“ID_”, “IDM_”, “IDP_”, “IDR_”, “IDD_” and “IDW_” by prefixing a single character ‘H’ to them. Also,<br />

the values of these help IDs are generated by adding a fixed number to the corresponding resource IDs.<br />

This fixed number is different for different types of IDs. For example, for “ID_XXX” and “IDM_XXX”<br />

types of IDs, 0x10000 will be added to the resource ID; for “IDP_XXX” type IDs, 0x30000 will be added;<br />

for “IDR_XXX” and “IDD_XXX” types of IDs, 0x20000 will be added; for “IDW_XXX” type IDs,<br />

0x50000 will be added.<br />

By default, the IDs of the common controls in a dialog box all start with “IDC_” prefix, which is not<br />

included in the default mapping. This means we must generate help IDs by ourselves. Actually, this can be<br />

easily achieved. If we open file “Makehelp.bat” (in our case, this file should be located in “16.2\Help\”<br />

directory), we will see that the help IDs are generated through “Makehm” utility, which can be executed<br />

under DOS prompt.<br />

“Makehm” has the following syntax:<br />

Makehm argument 1, argument 2, argument 3, argument 4 >> “File name”<br />

where<br />

argument 1:<br />

argument 2:<br />

argument 3:<br />

argument 4:<br />

prefix of resource ID<br />

prefix of help ID<br />

base number<br />

resource header file name<br />

For example, if we want to generate symbolic help IDs for those IDs prefixed with “IDC_”, and add<br />

0x10000 to the resource IDs to generate actual help IDs, we can execute this command as follows (Here,<br />

the application resource header file name is “resource.h”, and the “.hm” file name is “Help.hm”, it is<br />

located under the directory of “Hlp”):<br />

Makehm IDC_, HIDC_, 0x10000, resource.h >> “hlp\Help.hm”<br />

If we include the above statement in file “Makehelp.bat”, after executing it, we will see that all the<br />

common controls will have corresponding help IDs in file “Help.hm”.<br />

Enabling Context Sensitive Help for Common Controls<br />

In sample 16.2-1\Help, a dialog box IDD_DIALOG is added to the project. The dialog box supports<br />

context sensitive help implementation. There are four controls included in the dialog box: edit box<br />

IDC_EDIT, radio button IDC_RADIO, combo box IDC_COMBO and a push button IDC_BUTTON. After adding the<br />

“Makehm” command to “Makehelp.bat” file and executing it, we will see the following help IDs in file<br />

“Help.hm”:<br />

// Common Controls (IDC_*)<br />

HIDC_EDIT<br />

HIDC_BUTTON<br />

0x103E8<br />

0x103E9<br />

487

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

Saved successfully!

Ooh no, something went wrong!