Defining More Than One Help Contents

Some applications may require more than one Help Contents topic, depending on the state of the application. For example, the interface and options in PIF Editor are different for Standard mode and Enhanced mode. Therefore, the Help offered by PIF Editor depends on which mode the user is running. When running in Standard mode, the user sees the Help Contents tailored to that mode, and the user see a different Help Contents when running in Enhanced mode.

If a Help file contains two or more Contents topics, the application can assign one as the default by using the context identifier and the HELP_SETCONTENTS value in a call to the WinHelp function.

The sample application Helpex applies a somewhat different model by defining a function that the application can use instead of WinHelp. This function sends the HELP_SETCONTENTS value and sets the Contents topic without opening Windows Help.

BOOL MyWinHelp(hwnd, lpHelpfile, wCommand, dwData)
HWND     hwnd;
LPSTR    lpHelpfile;
WORD     wCommand;
DWORD    dwData;
{
   static DWORD   ctxContents = (DWORD)-1L;

   if (wCommand == HELP_SETCONTENTS) {
      ctxContents = dwData;
      return (TRUE);
   }

   if (wCommand == HELP_CONTENTS && ctxContents != (DWORD)-1L) {
      WinHelp(hwnd, lpHelpfile, HELP_CONTEXT, ctxContents);
   }
   else {
      WinHelp(hwnd, lpHelpfile, wCommand, dwData);
   }

   if (wCommand != HELP_QUIT && ctxContents != (DWORD)-1L) {
      WinHelp (hwnd, lpHelpfile, HELP_SETCONTENTS, dwData);
   }

}

After the Contents topic is set, the application can use any WinHelp API, including HELP_CONTENTS.