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?
You can display your CHM help file without the Print button as follows:
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.fsToolBarFlags
member of the structure to exclude the HHWIN_BUTTON_PRINT
value.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With