locked
Context Help (F1) etc RRS feed

  • Question

  • Hi All,

    In the new MFC feature pack (C++), if I press F1 I get a ? cursor and you click on something and then it launches the app .chm help file.

    How do you change the behaviour so that pressing F1 will launch the help file for whatever is under the cursor?

    Thanks
    Friday, May 1, 2009 1:50 PM

Answers

  • Good god......

    Even with a keyboard accelerator you will not get the ON_COMMAND message for ID_CONTEXT_HELP.

    Instead you need to intercept it in the message pump of your mainframe:


    BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
    {
        if(pMsg->message == 0x4d)
        {
            // SHIFT+F1 Help
            if( GetKeyState(VK_SHIFT) < 0 )
            {
                CFrameWndEx::OnContextHelp();
                return(TRUE);
            }
        }

        return CFrameWndEx::PreTranslateMessage(pMsg);
    }

    Which will launch the ? cursor behaviour.

    Thanks to this code project article that had the magic number for the message to intercept! :)

    Thanks
    • Marked as answer by Mark Duffill Friday, May 1, 2009 2:51 PM
    Friday, May 1, 2009 2:51 PM

All replies

  • I found that the following in your mainframe direct the code to the right place:


        ON_COMMAND(ID_HELP_FINDER, &CFrameWndEx::OnHelpFinder)
        ON_COMMAND(ID_HELP, &CFrameWndEx::OnHelp)
        ON_COMMAND(ID_CONTEXT_HELP, &CFrameWndEx::OnContextHelp)
        ON_COMMAND(ID_DEFAULT_HELP, &CFrameWndEx::OnHelpFinder)

    However this results in Shift+F1 not launching the ? cursor.

    Hmmm adding a keyboard accellorator for Shift+F1 does not work either....

    Thoughts anyone?
    Friday, May 1, 2009 2:14 PM
  • Good god......

    Even with a keyboard accelerator you will not get the ON_COMMAND message for ID_CONTEXT_HELP.

    Instead you need to intercept it in the message pump of your mainframe:


    BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
    {
        if(pMsg->message == 0x4d)
        {
            // SHIFT+F1 Help
            if( GetKeyState(VK_SHIFT) < 0 )
            {
                CFrameWndEx::OnContextHelp();
                return(TRUE);
            }
        }

        return CFrameWndEx::PreTranslateMessage(pMsg);
    }

    Which will launch the ? cursor behaviour.

    Thanks to this code project article that had the magic number for the message to intercept! :)

    Thanks
    • Marked as answer by Mark Duffill Friday, May 1, 2009 2:51 PM
    Friday, May 1, 2009 2:51 PM