An application can display a Help button in any of the common dialog boxes by setting the appropriate flag in the Flags member of the structure for that common dialog box. Following are the structures for the common dialog boxes and the Help flag that corresponds to each structure:
Structure | Flag value |
OPENFILENAME | OFN_SHOWHELP |
CHOOSECOLOR | CC_SHOWHELP |
FINDREPLACE | FR_SHOWHELP |
CHOOSEFONT | CF_SHOWHELP |
PRINTDLG | PD_SHOWHELP |
If an application displays the Help button, it must process the user's request for Help. This can be done either in one of the application's window procedures or in a hook function.
If the application processes the request for Help in one of the application's window procedures, it must first create a new message identifier for the string defined by the HELPMSGSTRING constant. The application creates the new message identifier by calling the RegisterWindowMessage function and passing this constant as the single parameter. (For more information about processing registered window messages, see Section 4.5, “Using Find and Replace Dialog Boxes.”) In addition to creating a new message identifier, the application must set the hwndOwner member of the appropriate structure for the common dialog box so that this member contains the handle of the dialog box's owner window. After the message identifier is created and the hwndOwner member is set, the dialog box procedure notifies the window procedure of the owner window whenever the user chooses the Help button.
The following example processes a user's request for Help in the window procedure of its owner window. The if statement should be in the default: section of the switch statement that processes messages.
MyHelpMsg = RegisterWindowMessage(HELPMSGSTRING);
.
.
.
if (message == MyHelpMsg)
WinHelp(hWnd, "appfile.hlp", HELP_CONTEXT, ID_MY_CONTEXT);
If the application processes the request for Help in a hook function, it should test for the following condition in the WM_COMMAND message:
wParam == pshHelp
When this condition is true, the hook function should call the WinHelp function as shown in the preceding example. (To process Help in a hook function, you must include the header file DLGS.H in the source file that contains the hook-function code.)