Overwrite the default F1 Windows Help behavior

526 Views Asked by At

I have a simple MFC application, where I want to customize the Help Button functions provided by the application. When clicking on F1 or Help button, it opens up a Windows help support page by default. How can I disable this default behavior and have it show nothing?

By show nothing, I mean not show the default windows support page. Ideally, when I should press F1 or click on help button, it should open no windows.

2

There are 2 best solutions below

7
On BEST ANSWER
//Free the string allocated by MFC at CWinApp startup. 
//m_pszHelpFilePath is the member variable of CWinApp that stores the 
//location to default help window.
//initialize it to an empty string just to be extra sure that default windows 
//support page location is never found.
//This needs to be set before CWinApp::InitInstance() is called.

free((void*)m_pszHelpFilePath);
m_pszHelpFilePath = _tcsdup(_T(""))

In the MainFrame.cpp, declare the MessageMap:

BEGIN_MESSAGE_MAP(MainFrame, CWinApp)
ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
END_MESSAGE_MAP()

Then, call the OnCommandHelp() that is a message handler which will be used to process F1 when in disabled mode.

LRESULT  MainFrame::OnCommandHelp(WPARAM wParam, LPARAM lParam)
{
    CWnd *pWnd = GetFocus();
    if (pWnd != NULL)
    {
        CWinApp* theApp = AfxGetApp();
        CString helpFilePath = theApp->m_pszHelpFilePath;
        // we have a control with the focus, quit help display
        ::WinHelp(m_hWnd, helpFilePath, HELP_QUIT, NULL);
        return TRUE;
    }
    return FALSE;        // let default handling process it
}

Here, WinHelp() is called which launches Windows Help (Winhelp.exe) and passes additional data that indicates the nature of the help requested by the application. HELP_QUIT as one of its parameters, closes the default windows help support page requested.

Also, don't forget to declare the OnCommandHelp() in MainFrame.h :

afx_msg LRESULT OnCommandHelp(WPARAM wParam, LPARAM lParam);
4
On

15-Mar-2006 — MS Announce WinHelp to be Deprecated. During discussions with MVPs, Microsoft Help team announced today that WinHelp would be deprecated (phased out). WinHelp is architected in such a way that we would have to rewrite it from the ground up to meet the Vista code standards. And that approach doesn't make sense given that we have two other Help systems in Vista.

For further information see also for your needs:

Following text below was quoted from:

The Windows Vista and Windows Server 2008 Developer Story: Application Compatibility Cookbook

Help Engine Support

Microsoft is committed to providing Help and Support technology in the Windows Platform and will continue to investigate new solutions for software developers. The following information clarifies the support in Windows Vista and Windows Server Codename "Longhorn" for four Microsoft Help technologies: Windows Help, HTML Help 1.x, the Help and Support Center, and the Assistance Platform client.

Windows Help—WinHlp32.exe

Windows Help WinHlp32.exe is a help program that has been included with Microsoft Windows versions starting with the Microsoft Windows 3.1 operating system. The Windows Help program (WinHlp32.exe) is required to display 32-bit help content files that have the ".HLP" file name extension. Windows Help is being deprecated for Windows Vista and Windows Server Codename "Longhorn." To view 32-bit Help files with the .HLP file name extension in Windows Vista and Windows Server Codename "Longhorn", you will need to download and install WinHlp32.exe from the Microsoft Download Center. Microsoft strongly recommends that software developers discontinue using the Windows Help application in Vista. Software developers who ship programs that rely on .HLP files are encouraged to transition their Help experience to an alternative Help file format, such as CHM, HTML, or XML. You will also need to change your calls from the WinHelp() API to the new content source. Several third-party tools are available to assist authors in converting content from one format to the other.

HTML Help 1.x (HH.exe)

Microsoft HTML Help 1.x (HH.exe) is a Help system included in Windows releases starting with Windows 98. HTML Help is required to display compiled Help files with the .CHM file name extension. HTML Help will ship in Windows Vista and Windows Server Codename "Longhorn." However, only critical updates to the engine will be made. No new features or feature improvements will be added to the HTML Help engine for Windows Vista and Windows Server Codename "Longhorn" or future Windows releases.