You create a sample MFC feature pack based SDI/MDI application with context sensitive help support. However, the context sensitive help may not work with submenu items. This blog attempts to get this working.
Figure 1: Context sensitive help for submenu item “View | Application Look | Office XP”
By default, when you create a sample MFC feature pack SDI/MDI application, the framework creates all the help files (.htm, .hhk, .hhp) with correct mapping for the top level menu items, including “ File | New”, “View | Status Bar”, etc. However, we don’t see any of these files created for submenu items. Now, since the files were not created for the submenu items, the help APIs could not find them and hence context sensitive help do not work and we may get unexpected results. If you manually create the help files (.htm) with correct mappings (.hhp) this will work.
Here are the steps to get this working:
Step 1: Create an .htm file associated with the submenu item in the directory “\hlp” where other .htm files are located.
Step 2: Name the file in format h[submenu item ID].htm . For example, hid_view_applook_off_xp.htm. Here ID_VIEW_APPLOOK_OFF_XP is the submenu item ID which we can get from Properties.
Step 3: Edit the file with the required help content. You can also copy the contents from existing .htm file for reference.
Step 4: Add this newly created .htm file in the project under “HTML Help Files” section.
Step 5: Edit the application .hhp file and add the file and mappings for the .htm file under “[FILES]” section and “[ALIAS]” section
Step 6: Rebuild the project
Step 7: Start the application and float over the mouse on the submenu item and hit “F1”. You will see the help file!
Unfortunately for an MDI application, you have to additionally tweak the code to handle the OnHelpInfo() due to a known issue in MFC Library. The reason for the MDI application to fail is related to the fact that CMDIChildWnd derives from CFrameWnd, so it has an m_nIDTracking and implements IsTracking(). When the OnCommandHelp() method is called on the CMDIChildWnd, the implementation in the CFrameWnd class is called, but the CMDIChildWnd does not have the tracking ID set. Due to this AFX_IDS_IDLEMESSAGE incorrectly gets assigned to CFrameWnd::m_nIDTracking instead of the submenu item ID. If you wish to know how the tracking is done, have a look at below code snippet, part of “C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\src\mfc\winfrm.cpp” @ 272. The commented line number 6 shows the expected path of execution for an SDI application. Because the tracking is incorrect, the code path in line number 9 executes and hence the problem with MDI.
One of the way to work-around this behavior is to override the OnHelpInfo() function in the main frame class as below. The fix is to defer to the parent frame, to get the tracking ID, if the CFrameWnd is really a CMDIChildWnd. This could be achieved using below code snippet.
Now your MDI application will fully support context sensitive help for submenu items as well. To know more information on Context-Sensitive Help for your programs, see http://msdn.microsoft.com/en-us/library/dyd1yfww(VS.80).aspx
- Gaurav Patole
Technical Lead, Developer Support – Languages Team.