Have you ever noticed how Office 2003, and a wide variety of modal dialogs throughout Windows XP and Windows 2003 Server use that little question mark button in the title bar to launch their F1 help system? It's rather neat, unobtrusive, and it allows you to get rid of a clunky-looking button on your forms that say “Help.”

Ok great, so you have seen it. Or maybe you're looking right now. No worries; I'll wait. Anyway, perhaps you're wondering now how to do this. It's a little more tricky to set up than you might think. The default behavior of the Help button in a window title bar is to launch a “what's this?” cursor. Hmm, not very useful. I honestly don't remember the last time I used the “what's this” help for anything, quite frankly.

The trick to solving this problem is to override the WndProc() method on your Form subclasses. When the title bar help button is clicked, it sends a message to your Form with a WParam value of SC_CONTEXTHELP. SC_CONTEXTHELP is defined in some native Windows header file or another, you're welcome to search for it on MSDN if you really want. By looking for, and then acting upon, this WParam value, you can launch your F1 help topics just like Office (I wonder if that's a trademarked term somewhere...).

Just one more tiny step towards consistent UI across Windows apps ;-).

/** Added WM_SYSCOMMAND check. **/

using System;
using
System.Windows.Forms;

public class
HelpForm : Form
{
    private const int
SC_CONTEXTHELP = 0xF180;
    private const int WM_SYSCOMMAND  = 0x0112;

    public
HelpForm()
    {
        this.ClientSize = new
System.Drawing.Size(300,250);
        this.HelpButton = true
;
        this.MaximizeBox = false
;
        this.MinimizeBox = false
;
        this
.Name = "HelpForm";
        this
.Text = "Help Form";
    }

    protected override void WndProc(ref
Message m)
    {
        if (m.Msg == WM_SYSCOMMAND && SC_CONTEXTHELP == (int
)m.WParam)
            ShowHelp();
       
else
           
base.WndProc(ref
m);
    }

    private void
ShowHelp()
    {
        MessageBox.Show("F1 Help goes here.");
    }

    [STAThread]
    static void
Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new
HelpForm());
    }
}