FILE: Help95.exe Implements Windows 95 Style Help

Last reviewed: September 30, 1997
Article ID: Q167698
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++, 32-bit Editions, versions 4.2, 4.2b, 5.0

SUMMARY

Windows 95 provides support for context-sensitive help by means of the messages WM_HELP and WM_CONTEXTMENU. It also provides a new style WS_EX_CONTEXTHELP that has the effect of adding a question mark button to the windows caption bar of a dialog. The HELP95 sample shows how these messages can be used to show context Help for a window.

The sample includes the file help95.hpj that contains the following line:

   #include <c:\msdev\mfc\include\afxhelp.hm> // for VC++ 4.xx

   -or-

   #include <c:\devstudio\VC\MFC\include\afxhelp.hm> // for VC++ 5.00

This assumes that the Visual C++ compiler is installed in C:\MSDEV (for Visual C++ 4.xx) or C:\DEVSTUDIO\VC (for Visual C++ 5.00) directory. You may need to modify this line to reflect the correct path.

The following file is available for download from the Microsoft Software Library:

 ~ Help95.exe (size: 141131 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from
               Online Services

NOTE: Use the -d option when running HELP95.EXE to decompress the file and recreate the proper directory structure.

MORE INFORMATION

In 16-bit MFC, applications implemented context-sensitive Help by using the accelerator keys F1 and SHIFT+F1 that generated WM_COMMAND messages with IDs ID_HELP and ID_CONTEXTHELP, respectively. This, together with the MFC private messages WM_COMMANDHELP and WM_HELPHITEST, was used to bring up context Help for an application.

Windows 95 makes this process easier by providing the WM_HELP message that gets sent each time the user presses the F1 key, giving the application a chance to bring up Help information on the control that has the keyboard focus or on the dialog box itself. This new WM_HELP message is not limited to dialog boxes alone; it gets sent to any window that has keyboard focus or to the currently active window.

Windows 95 also provides the new style WS_EX_CONTEXTHELP that adds a question mark button to a dialog's caption bar. When a user clicks on this button, the cursor changes to a question mark with a pointer. If the user then clicks on a control on the dialog box, a WM_HELP message is sent to it. The control passes this message on to its parent, which should then handle this message and call WinHelp() with HELP_WM_HELP. This displays a pop-up window with the Help text for the control.

There is also the WM_CONTEXTMENU message that gets sent whenever the user right-clicks on a window. This message is typically used to display a pop-up menu using TrackPopupMenu(). It can also be used to display context Help by calling WinHelp() with the parameter HELP_CONTEXTMENU. This has the effect of displaying a pop-up menu with a "What's This?" entry. Selecting this option then displays a pop-up window with Help text for the window.

HELP95 is an MFC MDI application with form views for MDI child windows. The application shows how to bring up context Help for form views, dialogs, common dialogs, and property sheets.

Context Help for dialogs and form views is pretty straight-forward. It requires that the user handle the WM_HELP or WM_CONTEXTMENU message and call WinHelp(). Make sure the Help ID is checked for each of the controls in the resource editor. In case of WM_HELP message, the lParam points to a HELPINFO structure that contains information about the menu item, control, dialog box, or window for which help is requested. For WM_CONTEXTMENU messages, there is no HELPINFO structure with all the information so the API calls GetDlgCtrlID() and GetWindowContextHelpId() are needed to give the required information.

In case of property sheets, it is slightly more complicated. Adding Help IDs to controls on a property page using the resource editor causes the DIALOGEX resource to be used instead of the DIALOG resource. But Windows does not support the creation of property sheets with the DIALOGEX resource. To work around this, the Help IDs are added programmatically after the creation of the property sheet and property pages. Also, because there is no property sheet template, the WS_EX_CONTEXTHELP style has to be set programmatically. The handling of the WM_HELP and WM_CONTEXTMENU messages remains the same.

REFERENCES

MFC Technical Note 28: "Context-Sensitive Help Support"

For more information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q125670
   TITLE     : How to Implement Context-Sensitive Help in Windows 95
               Dialogs

   ARTICLE-ID: Q149343
   TITLE     : How to Implement Context-Sensitive Help for Dialog
               Controls

   ARTICLE-ID: Q138505
   TITLE     : How to Add Context-Sensitive Help Button to Windows 95
               Dialogs

   ARTICLE-ID: Q110506
   TITLE     : SAMPLE: Context Sensitive Help in a CDialog

   ARTICLE-ID: Q140676
   TITLE     : PRB: ClassWizard Uses WM_HELPINFO Instead of WM_HELP

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Jaganathan Thangavelu, Microsoft Corporation
Keywords          : MfcMisc kbcode kbsample kbfile
Technology        : kbMfc
Version           : WINDOWS NT: 4.2, 4.2b, 5.0
Platform          : NT WINDOWS
Issue type        : kbhowto
Solution Type     : kbfile


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.