How A Help File Maker Adds Context Sensitive F1 Support
Press F1 in a Windows program, and the help can open on the topic for the screen in front of you. That is context-sensitive help, and it depends on a chain that has to be built and kept in step. Each screen or control carries a number, which has to point to one help topic in a file the application can call at runtime. Setting up and maintaining that chain by hand across a large program is slow and easy to break. A help file maker builds the mapping and generates the file your developers use in the application. When topics or IDs change, the map file can be generated again from the current project.
How F1 Finds the Right Topic
The Context ID and the Map File
Context-sensitive help rests on two pieces. The first is a context ID, a unique number assigned to a screen or control. Microsoft’s guidance is that a developer records these in a header (.h) file listing the symbolic and numeric IDs for every dialog and control, with each numeric value unique (Microsoft, HTML Help Workshop guidelines). The second piece is the mapping inside the help project that ties each number to a topic in the compiled CHM. Together they let a number stand in for a topic, so the program never has to know a file name.
The API Call Behind F1
At runtime the application calls the HtmlHelp() function, declared in htmlhelp.h and exported by hhctrl.ocx, which “displays a help window” (Microsoft, HTML Help API). To open a topic by its number, the program passes the HH_HELP_CONTEXT command and the context ID for the current screen, and the viewer shows the topic mapped to that number. This is the call a help file maker’s output plugs into. The tool produces the numbers and the mapping, and the developer wires the F1 key to this function.
Building the Mapping Without Breaking It
The File Developers Need
In Dr.Explain, this is handled in the Help Context ID management section of the project settings, which generates the file the developers compile against (Dr.Explain, Help Context ID management). From there, it produces:
- A map file in the team’s language, as C or C++ (.h), C# (.cs), Visual Basic (.vb), or Object Pascal (.inc).
- Named constants the code passes to HtmlHelp() in place of raw numbers, which keeps the source clear.
- A hexadecimal mode for code that expects the IDs in that form.
The IDH Convention and the Compile-Time Check
Microsoft’s guideline adds a naming rule worth keeping. If you prefix each topic ID with IDH, HTML Help Workshop checks at compile time that every mapped topic exists in the finished CHM, and that each context topic is listed in the project file (Microsoft, HTML Help Workshop guidelines). That gives the developer a compile-time check for a broken mapping before the CHM reaches users. Dr.Explain also builds the aliases, the symbolic names that stand in for each number, from templates as you add pages, so a new screen does not mean inventing an ID by hand.
Where Context Help Breaks, and How Mapping Helps
Where Manual Maps Fail
The setup is the easy part. Microsoft’s own troubleshooting list identifies several mapping problems: an ID mapped in the project with no matching topic in the CHM, a topic that exists but was never mapped, or a symbolic ID in one file that does not match the other. These problems can appear when writers rename topics, merge them, or add screens between releases without updating the related IDs and mappings. When it does, F1 can open the wrong page or nothing at all. Keeping the IDs and mappings aligned becomes important as the application and its documentation change.
What the Tool Automates, and What It Does Not
When the documentation changes, the map file can be generated again from the current project, giving developers an updated set of IDs and constants to use in the application. This reduces the amount of manual mapping they need to maintain. The developer still writes the F1 handler that calls HtmlHelp(), and someone still decides which topic answers which screen. For desktop software, opening the relevant help topic directly gives users a faster way to understand the screen or control they are working with.
