3

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.

Urvashi Gupta
  • 444
  • 4
  • 13

2 Answers2

2
//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);
Urvashi Gupta
  • 444
  • 4
  • 13
  • 1
    Nope. This was the situation I was in. I did not want the default windows support page to show up. Maybe I didn't explain the question well. But the intend was that when I press F1 or click on Help button, it should do nothing (meaning doesn't show default window support page). – Urvashi Gupta Oct 11 '17 at 22:44
  • 1
    Moreover, I don't have any 100's or 1000's of rep points anyway. I don't care about gaining "points" out of it. Just wanted to help anyone who might be facing the same issue. Because I spent a great deal of time trying to figure this out. – Urvashi Gupta Oct 11 '17 at 22:47
  • Also, how does it do otherwise? And yes it invokes WinHelp but how is that wrong? If you look at the parameters, it is using HELP_QUIT, which quits the default window support page.I have tested this and it works great like intended. – Urvashi Gupta Oct 11 '17 at 22:55
  • As @David mentioned WinHelp is a help system from the 20th Century. You need to convert from WinHelp to HTMLHelp. Your solution posted as answer is good to chuck away context-sensitive help of your application only. Have a look at [How to convert HLP files in CHM files](https://stackoverflow.com/a/43643026/1981088). Please search StackOverflow before asking. – help-info.de Oct 12 '17 at 07:54
  • Ah! interesting. I didn't read anywhere on MSDN, that winhelp is advised to be not used, or that its a 20th Century system that makes it not cool. I mean all our famous programming languages are 20th century old system. Anywho, would love to get the reference on the MSDN page that talks about why to move to HTMLHelp. Also, didn't know it was a thing that I need to look up on StackOverflow. Was looking for solution to this problem, to be honest. And just using WinHelp to quit the existing help project file. Doing nothing else with WinHelp. – Urvashi Gupta Oct 12 '17 at 16:17
  • 2
    Why not just have your handler do nothing and return `TRUE`? – Raymond Chen Oct 12 '17 at 18:23
  • You say ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp) I didn't have WM_COMMANDHELP, as it is defined in . Before I found that, I tried WM_HELP and it achieved very similar results. In my case I'm intercepting this to open a web page instead of local help. – Swiss Frank May 27 '19 at 03:04
2

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.

help-info.de
  • 6,695
  • 16
  • 39
  • 41
  • Right! Those who want to "display" their help files. Those who have a .hlp project and want to have a reliable way of displaying information. They should definitely use HTMLHelp(). You are correct in that. WinHelp() should not be used to HELP_CONTEXTPOPUP for example or other calls as the format will not be supported . But for this question, you are asking me to first convert Windows default help project to a HTML Help view project format. Only to *not* display that format? When I don't want to display that .hlp project why do I need to convert to a "right" format? – Urvashi Gupta Oct 12 '17 at 17:59
  • 1
    You do not have to migrate WinHelp => HTMLHelp in any case - it's just a suggestion to clean your MFC project from WinHelp. – help-info.de Oct 12 '17 at 18:07
  • Oh I see. I will try that now. Thank you for the suggestion. – Urvashi Gupta Oct 12 '17 at 19:05
  • My pleasure - really old help authoring stuff - as me. Please check as answered when the answer was helpful Upvoting is welcome. Have a nice weekend. – help-info.de Oct 13 '17 at 07:54