Click here to Skip to main content
12,827,242 members (43,644 online)
Click here to Skip to main content
Articles » Languages » C# » Windows Forms » Downloads


48 bookmarked
Posted 26 Apr 2011

C# WinForms Application Full Integration with HTMLHelp ( .chm ) - Help Topics, Context Sensitive Help, and Tooltips

, 4 May 2011 CPOL
Use HTMLHelp (.chm) to display help topics, context sensitive help and tooltips in C# Winform application
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WinHelpLib

    /// <summary>
        TableOfContents - opens table of contents tab only - keyword is unused
        Topic - opens a topic in the current tab - keyword is the path to the topic
        TopicId - opens a topic in the current tab - keyword is the id (numeric only) of the topic in the [MAP] section (.h file)
        Index - opens the index tab - keyword fils the edit and selects accordingsly in the list below withouth chaning the displayed topic 
        Find - opens the find tab - keyword is unused
        AssociateIndex - does not seem to work properly 
        KeywordIndex - opens a topic in the current tab (sometimes changes to index tab) - keyword (sometimes changes the textbox and list index in index tab) changes the displayed topic to the selected one 
    /// </summary>

    class HTMLHelpEx

        const int HH_DISPLAY_TEXT_POPUP = 0x000E;

        struct Point
            public Int32 x;
            public Int32 y;

        struct Rect
            public Int32 left;
            public Int32 top;
            public Int32 right;
            public Int32 bottom;

        struct HH_POPUP
            public Int32 cbStruct;
            public IntPtr hinst;              //4 bytes on x86, 8 on x64
            public UInt32 idString;
            [MarshalAs(UnmanagedType.LPWStr)] //Unicode
            public String pszText;
            public Point pt;
            public UInt32 clrForeground;
            public UInt32 clrBackground;
            public Rect rcMargins;
            [MarshalAs(UnmanagedType.LPWStr)] //Unicode
            public String pszFont;

        [DllImport("hhctrl.ocx", CharSet = CharSet.Unicode, EntryPoint = "HtmlHelpW")]
        static extern IntPtr HtmlHelp(
           IntPtr caller,   //4 bytes on x86, 8 on x64
           String file,
           uint command,
           IntPtr data      //4 bytes on x86, 8 on x64

        string sHelpFileName;
        string sCSStreamName;

        public HTMLHelpEx(string sName,string sCSName)
            sHelpFileName = sName;
            sCSStreamName = sCSName;

        public void ShowHelp(Control ctrl, HelpNavigator hn, object oKeyword)
            Help.ShowHelp(ctrl, sHelpFileName, hn, oKeyword);

        public void ShowContextHelp(uint idString, Control ctrl)
            HH_POPUP sPUp = new HH_POPUP();

            sPUp.cbStruct = Marshal.SizeOf(sPUp);
            sPUp.hinst = IntPtr.Zero;
            sPUp.idString = idString;
            sPUp.pszText = String.Empty;
   = new Point()
                x = ctrl.PointToScreen(new System.Drawing.Point()).X,
                y = ctrl.PointToScreen(new System.Drawing.Point()).Y
            sPUp.clrForeground = 0;
            sPUp.clrBackground = 0;
            sPUp.rcMargins = new Rect()
                left = 10,
                top = 10,
                right = 10,
                bottom = 10

            IntPtr ptrData = Marshal.AllocHGlobal(Marshal.SizeOf(sPUp));
            Marshal.StructureToPtr(sPUp, ptrData, false);
            IntPtr Result = HtmlHelp(ctrl.Handle, sHelpFileName + "::/" + sCSStreamName, HH_DISPLAY_TEXT_POPUP, ptrData);//(UInt32)


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Veselin Tenev
Software Developer (Senior)
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170326.1 | Last Updated 5 May 2011
Article Copyright 2011 by Veselin Tenev
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid