5

I'm performing maintenance on a legacy MFC application. We have a need to disable the Print button in the Help dialog. There is no printer connected to the system and the application crashes if the user presses the Print button in the help window.

The code just uses the standard HtmlHelpA method to bring up the Windows Help dialog:

void CNiftyView::OnHelp() 
{
   CString csHelpFile;
   csHelpFile.Format( "%s/NiftyHelp.chm", NiftyDoc::GetHelpPath() );
   ::HtmlHelpA( m_hWnd, csHelpFile, HH_HELP_CONTEXT, IDH_NIFTY_SECTION );
}

I've found information that we can suppress the Print button with some code in the Help HTML stylesheet (http://www.sagehill.net/docbookxsl/HtmlHelp.html). But that would require recompiling the help file, and I'd prefer to not do that. I also found some information that says you can customize the HTML Help Viewer by manipulating each pane's HH_WINTYPE structure, but no information on how you actually do that (http://msdn.microsoft.com/en-us/library/ms524435%28v=vs.85%29.aspx).

Is there some way to disable that Print button in the HTML Help viewer programatically?

Frecklefoot
  • 1,660
  • 2
  • 21
  • 52
  • 1
    *"There is no printer connected to the system and the application crashes if the user presses the Print button in the help window."* This strikes me as weird. Surely the HTML Help team tested for the case where no printer was connected to the machine. In fact, I'll bet their dev machines probably didn't have a printer hooked to them. Does the system crash when *other* print buttons are clicked? – Cody Gray - on strike Apr 08 '13 at 22:06
  • Does HTML Help crash when you try to print within the help of some other application than yours ? – Jabberwocky Apr 09 '13 at 07:42
  • I think it's weird too. It's hard to find another app to print from because this is an embedded system (WES7) and doesn't contain the standard layout of apps such as Notepad or WordPad. – Frecklefoot Apr 09 '13 at 19:02

1 Answers1

6

You can display your CHM help file without the Print button as follows:

  • Call HtmlHelp with the HH_GET_WIN_TYPE command to get a pointer to a HH_WINTYPE structure containing the HTML Help Viewer parameters defined in your CHM file.
  • Copy the returned structure. (Modifying the returned structure directly won't work.)
  • Modify the fsToolBarFlags member of the structure to exclude the HHWIN_BUTTON_PRINT value.
  • Pass the modified HH_WINTYPE structure back to the HtmlHelp function using the HH_SET_WIN_TYPE command.

Example C++ code*:

HH_WINTYPE *pwt = NULL;
LPCWSTR pszFile = L"MyFile.chm";
LPCWSTR pszWin = L"MyFile.chm>Main"; // "Main" is the window type defined in the CHM file

// Get the window type definition
HWND hWndHelp = HtmlHelp(NULL, pszWin, HH_GET_WIN_TYPE, (DWORD) &pwt);

if (pwt) {
    // Copy the contents of the returned structure
    HH_WINTYPE wt = *pwt;

    // Remove the "Print" toolbar button from the window definition
    wt.fsToolBarFlags &= ~HHWIN_BUTTON_PRINT;
    wt.cbStruct = sizeof(wt); // force the correct size

    // Set the new window type
    hWndHelp = HtmlHelp(NULL, pszFile, HH_SET_WIN_TYPE, (DWORD) &wt);

    // Display help
    hWndHelp = HtmlHelp(NULL, pszFile, HH_DISPLAY_TOPIC, NULL);
}

I almost don't know C++, so it's very amateur code. Please fell free to edit and improve it.

More examples of using HH_WINTYPE, HH_GET_WIN_TYPE and HH_SET_WIN_TYPE:
How To Programmatically Create a Tri-pane HTML Help Window
How to use the unmanaged HTML Help API from a managed Visual C# application

Helen
  • 87,344
  • 17
  • 243
  • 314
  • 1
    It should be noted that users who want to print CHM file will click Options button and select "Print" from pop-up menu. You might want to remove "Options" button as well: `wt.fsToolBarFlags &= ~(HHWIN_BUTTON_PRINT | HHWIN_BUTTON_OPTIONS);` – izogfif Aug 28 '15 at 14:46