Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://social.msdn.microsoft.com/Forums/en-US/8c82991d-ac7e-4f10-b875-3522dace10c0/f1-key-results-in-two-calls-to-cmainframeonhelp" rel="nofollow">Apperently this person found the same issue</a> and talks about the cause and effect.</p> <blockquote> <p>This double event handling is due to some legacy code.</p> <p>Windows automatically translates F1 key into WM_HELP messages since Windows 95 (the support article mentioned by Viorel_). The processing you noticed with the 0x4d message does exactly that; this is some Windows code. Then, when an application receives a WM_HELP message, it (can) handle it by calling WinHelp.</p> <p>Before Windows 95, WM_HELP message did not exist. The only way to handle F1 was to create a VK_F1 shortcut, and add a handler for it. Windows 95, by adding the WM_HELP message, made the help management easier. Since Win95, you don't have to create a VK_F1 shortcut for ID_HELP anymore. </p> <p>The MFC Appwizard still adds this shortcut if you select "Context Sensitive Help" option though. MFC are older than Windows 95! If you create an MFC Appwizard application using context sensitive help, a shortcut is created for VK_F1, associated with CFrameWnd::OnHelp(), which routes WM_HELP messages to the frame windows of the application. "So far so good".</p> <p>But Windows also automatically translate F1 keystroke into WM_HELP messages. So CFrameWnd::OnHelp() is called once again, because WM_HELP event is handled by the MFC.</p> <p>If you don't want to be called twice, remove the keyboard shortcut in your resource file and handle WM_HELP instead. Then you will have the following process:</p> <ul> <li><p>Windows catches F1 key, generates WM_HELP</p></li> <li><p>A message handler for WM_HELP (ON_WM_HELPINFO) in your code catches WM_HELP messages. MFC default message processing for WM_HELP is to send a WM_COMMAND(ID_HELP) message (this is another funny part!)</p></li> <li><p>A message handler for WM_COMMAND(ID_HELP) in your code calls default MFC processing. This runs winhelp.</p></li> </ul> <p>The following CMainFrame code doesn't handle twice help messages:</p> <pre><code>ON_WM_HELPINFO() ON_COMMAND(ID_HELP, &amp;CMDIFrameWndEx::OnHelp) .. BOOL CMainFrame::OnHelpInfo(HELPINFO* pHelpInfo) { return CMDIFrameWndEx::OnHelpInfo(pHelpInfo); } </code></pre> <p>And don't forget to remove the shortcut for VK_F1 in the resource file!</p> </blockquote> <p>Don't upvote this post, <a href="http://social.msdn.microsoft.com/Forums/en-US/8c82991d-ac7e-4f10-b875-3522dace10c0/f1-key-results-in-two-calls-to-cmainframeonhelp" rel="nofollow">follow the link and upvote the origional post</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload