launching a Help file from within a win 32 program
ok simple problem i hope...
i'm doing a program in windows going fine but now i have to launch a help file (the standard windows type) ive created it using MS HTML workshop all compiled all works etc but in SIMPLE terms as this is my first windows program how do i do it...
help file from menu is called ID_HELP by the way and help file is called help.chm
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Re: launching a Help file from within a win 32 program
To open a chm file, you can use the HtmlHelp function that is exported by the ocx (an ocx is just a normal dll that export ActiveX objects) HHCtrl.ocx.
I have only found on msdn, the declaration in visual basic of the function:
Code:
Declare Function HtmlHelp Lib "HHCtrl.ocx" Alias "HtmlHelpA" _ (ByVal hwndCaller As Long, _ ByVal pszFile As String, _ ByVal uCommand As Long, _ dwData As Any) As Long
But i have not found the declaration in C.
There is a little problem, because i don't know how to import functions from a file with a .ocx extension from a def file (if anyone know, he can says me how).
So, you can get a static library which import functions from the HHCtrl.ocx file:
Use implib from a dos prompt in the directory of your project like that:
implib -c hhctrl.lib %windir%\system\HHctrl.ocx
Or for Windows NT, 2000, XP
implib -c hhctrl.lib %sysdir%\HHCtrl.ocx
I am not sure that %sysdir% is defined in the windows NT, 2000, or XP environment, but i think so.
And now, here is an example of program using HtmlHelp function:
The declarations, are perhaps not exactly correct, since i have not found any web site that exactly declare the function.
You must link your program to the HHCtrl.lib file.
My includes files are old, so i have not the ULONG_PTR type, and i have typedefed it to LPTSTR in my project. I have finally removed this typedef, before posting the code. Theorically, this code must compile on your computer.
I, now explains the parameters of HtmlHelp.
BOOL WINAPI HtmlHelpA(
HWND hWndCaller,
LPCSTR pszFile,
UINT uCommand,
ULONG_PTR pszTopic);
hWndCaller, is a handle to a window which become the parent of the window created by the help library.
It works like the first parameter of the MessageBox function or the hWndParent of the DialogBox function.
In the example, it is set to the desktop window (it can also be set to NULL, but i don't know if it is really documented).
pszFile if a pointer to the path to the .chm file. If the path is not absolute, it searches the file firstly in the current directory, and if it does not find the file, it searches in the help directory (localised in %windir%).
uCommand
Set of flags that describe what topic is showed in the help file.
if HH_DISPLAY_TOPIC is set (that is the default case, because HH_DISPLAY_TOPIC=0), than the pszTopic parameter is a pointer to a string that represents the URL of the html file within the .chm.
if HH_HELP_CONTEXT is set, then the pszTopic parameter is an integer that represents the integer identifier of the topic.
if HH_DISPLAY_TOC is set, the help is opened with the table of contents tab selected.
if HH_DISPLAY_INDEX is set, the help is opened with the index tab selected.
if HH_DISPLAY_SEARCH is set, the help is opened with the search tab selected.
I have not searched the meaning of other flags (i have just found these flags on internet, searching with google).
I have looked to the threads and processes, and see that when the function is called, two new threads are created.
And two calls to the HtmlHelp function, don't create more threads.
One of the two threads, is used for creating the windows.
What is strange, is that the help browser blocks when the main thread is busy (i have tested that with a call to Sleep).
There is a second method to call the help browser:
Launch the hh.exe application. This application has command-line parameters mapid which identify the context ID, of the help.
You must call CreateProcess to do that.
Re: launching a Help file from within a win 32 program
Originally Posted by SuperKoko
Excuse me Bond, i was typing my post when you posted.
No problem. You're much more thorough than me!
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Re: launching a Help file from within a win 32 program
The above seems like an overly complicated solution. Why not just add the Include and Lib directories that are included with HTML Help Workshop to your project, and include the lib and header file in your project, whammo done. I was searching around Google and there are several misleading posts which seem to imply that HTML Help doesn't work out-of-the-box with WinAPI. This is not true, it works fine just including the provided header and lib.
Re: launching a Help file from within a win 32 program
Originally Posted by dhirallin
The above seems like an overly complicated solution. Why not just add the Include and Lib directories that are included with HTML Help Workshop to your project, and include the lib and header file in your project, whammo done. I was searching around Google and there are several misleading posts which seem to imply that HTML Help doesn't work out-of-the-box with WinAPI. This is not true, it works fine just including the provided header and lib.
It wasn't an overcomplicated solution 6 years ago (when the question was posted).
Bookmarks