Tutorial: How to Use HTML Help in .NET

J

James Hancock

In case any of you have been as frustrated with the Help implimentation in
..NET as me, here's a way around the stupidity of using the current window as
the parent for the help window (yes, you can't go back and forth and look in
the help file and then do what it says in the program! That would be to damn
easy!).

I found the best possible way to do all of this stuff. You could extend this
to handle events etc. if you wished but this is all I needed.

Here's all you need:

[DllImport("hhctrl.ocx", CharSet=CharSet.Auto, SetLastError=true)]

static extern IntPtr HtmlHelpW(

IntPtr hwnd,

string HelpFile,

int Command,

int TopicID);

[DllImport("hhctrl.ocx", CharSet=CharSet.Auto, SetLastError=true)]

static extern IntPtr HtmlHelpA(

IntPtr hwnd,

string HelpFile,

int Command,

int TopicID);

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]

static extern IntPtr GetDesktopWindow();

private const int HH_DISPLAY_TOC = 0x0001;

private const int HH_DISPLAY_INDEX = 0x0002;

private const int HH_DISPLAY_SEARCH = 0x0003;

private const int HH_DISPLAY_TOPIC = 0x000;



So you would call it like this:

if (System.Environment.OSVersion.Platform == System.PlatformID.Win32NT) {

HtmlHelpW(GetDesktopWindow(), "help.chm", HH_DISPLAY_TOPIC, 342342);

} else {

HtmlHelpA(GetDesktopWindow(), "help.chm", HH_DISPLAY_TOPIC, 342342);

}

GetDesktopWindow() forces it to be bound to the desktop so no stupidity.

The A is for Win9x and the W is for NT. (obviously)

If anyone is interested, I'll write up a small class.



James Hancock
 
M

Mattias Sjögren

James,
The A is for Win9x and the W is for NT. (obviously)

The whole point of using CharSet.Auto is that you don't have to pick A
or W version of an API manually, the runtime does that for you. So a
single declaration without the A or W suffix should work.



Mattias
 
J

James Hancock

Tried that. It doesn't for some reason. My guess is becasue it's an OCX that
it's introping with and not a .dll

James Hancock
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top