home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- * File name : help.c
- *
- * Description: This module contains all the routines for interfacing
- * the IPF Help Manager.
- *
- * Project: OS/2 PM Port of GNU CHESS 4.0 (PmChess)
- *
- * Version: 1994-4-17
- *
- * Module: Help Module
- *
- * System: OS/2 2.11 using emx0.8h
- *
- * Porter: Revised and ported to OS/2 2.1 by Yibing Fan
- *
- * This source file contains the following functions:
- *
- * InitHelp()
- * HelpIndex()
- * HelpGeneral()
- * HelpUsingHelp()
- * HelpKeys()
- * HelpTutorial()
- * HelpProductInfo()
- * DisplayHelpPanel(idPanel)
- * DestroyHelpInstance()
- *
- * Concepts : help manager
- *
- * API's : WinLoadString
- * WinCreateHelpInstance
- * WinAssociateHelpInstance
- * WinSendMsg
- * WinDlgBox
- * WinDestroyHelpInstance
- * WinMessageBox
- * WinAlarm
- *
- * Files : OS2.H, STRING.H, MAIN.H, DLG.H, HELP.H, XTRN.H
- *
- *************************************************************************/
-
- /*
- * Include files, macros, defined constants, and externs
- */
-
- #define INCL_WINHELP
-
- #include <os2.h>
- #include <string.h>
- #include "pmchess.h"
- #include "resource.h"
- #include "help.h"
-
- #define HELPLIBRARYNAMELEN 20
-
- /* If DEBUG is defined, then the help panels will display their
- * id values on their title bar. This is useful for determining
- * which help panels are being shown for each dialog item. When
- * the DEBUG directive is not defined, then the panel ids are not
- * displayed.
- */
-
- /* #define DEBUG */
-
- /*
- * Global variables
- */
- extern HAB hab;
- BOOL fHelpEnabled; /* flag to determine if help is enabled */
- static HWND hwndHelpInstance;
- static CHAR szLibName[HELPLIBRARYNAMELEN];
- static CHAR szWindowTitle[HELPLIBRARYNAMELEN];
-
- /**************************************************************************
- *
- * Name : InitHelp()
- *
- * Description: Initializes the IPF help facility
- *
- * Concepts: Called once during initialization of the program
- *
- * Initializes the HELPINIT structure and creates the
- * help instance. If successful, the help instance
- * is associated with the main window.
- *
- * API's : WinLoadString
- * WinCreateHelpInstance
- * WinAssociateHelpInstance
- *
- * Parameters : [none]
- *
- * Return : [none]
- *
- *************************************************************************/
- VOID InitHelp(VOID)
- {
- HELPINIT hini;
-
- /* if we return because of an error, Help will be disabled */
- fHelpEnabled = FALSE;
-
- /* initialize help init structure */
- hini.cb = sizeof(HELPINIT);
- hini.ulReturnCode = 0;
-
- hini.pszTutorialName = (PSZ)NULL; /* if tutorial added, add name here */
-
- hini.phtHelpTable = (PHELPTABLE)MAKELONG(TEMPLATE_HELP_TABLE, 0xFFFF);
- hini.hmodHelpTableModule = 0;
- hini.hmodAccelActionBarModule = 0;
- hini.idAccelTable = 0;
- hini.idActionBar = 0;
-
- if(!WinLoadString(hab,
- (HMODULE)0,
- IDS_HELPWINDOWTITLE,
- HELPLIBRARYNAMELEN,
- (PSZ)szWindowTitle))
- {
- SMessageBox(hwndClient, IDMSG_CANNOTLOADSTRING, IDS_CHESS);
- return;
- }
-
- hini.pszHelpWindowTitle = (PSZ)szWindowTitle;
-
- /* if debugging, show panel ids, else don't */
- #ifdef DEBUG
- hini.fShowPanelId = CMIC_SHOW_PANEL_ID;
- #else
- hini.fShowPanelId = CMIC_HIDE_PANEL_ID;
- #endif
-
- if(!WinLoadString(hab,
- (HMODULE)0,
- IDS_HELPLIBRARYNAME,
- HELPLIBRARYNAMELEN,
- (PSZ)szLibName))
- {
- SMessageBox(hwndClient, IDMSG_CANNOTLOADSTRING, IDS_CHESS);
- return;
- }
-
- hini.pszHelpLibraryName = (PSZ)szLibName;
-
- /* creating help instance */
- hwndHelpInstance = WinCreateHelpInstance(hab, &hini);
-
- if(hwndHelpInstance == NULLHANDLE || hini.ulReturnCode)
- {
- SMessageBox(hwndFrame, IDMSG_HELPLOADERROR, IDS_CHESS);
- return;
- }
-
- /* associate help instance with main frame */
- if(!WinAssociateHelpInstance(hwndHelpInstance, hwndFrame))
- {
- MessageBox(hwndFrame,
- IDMSG_HELPLOADERROR,
- MB_OK | MB_ERROR,
- FALSE);
- return;
- }
-
- /* help manager is successfully initialized so set flag to TRUE */
- fHelpEnabled = TRUE;
- } /* End of InitHelp */
-
-
- /**************************************************************************
- *
- * Name : HelpGeneral()
- *
- * Description: Processes the WM_COMMAND message posted by the
- * General Help item of the Help menu.
- *
- * Concepts: Called from MainCommand when the General Help
- * menu item is selected.
- *
- * Sends an HM_EXT_HELP message to the help
- * instance so that the default Extended Help is
- * displayed.
- *
- * API's : WinSendMsg
- *
- * Parameters : [none]
- *
- * Return : [none]
- *
- *************************************************************************/
- VOID HelpGeneral(VOID)
- {
- /* this just displays the system extended help panel */
- if(fHelpEnabled)
- if(NULL != WinSendMsg(hwndHelpInstance, HM_EXT_HELP,
- (MPARAM)NULL, (MPARAM)NULL))
- MessageBox(hwndClient,
- IDMSG_HELPDISPLAYERROR,
- MB_OK | MB_ERROR,
- FALSE);
- } /* End of HelpGeneral */
-
- /**************************************************************************
- *
- * Name : HelpUsingHelp()
- *
- * Description: Processes the WM_COMMAND message posted by the
- * Using Help item of the Help menu.
- *
- * Concepts: Called from MainCommand when the Using Help
- * menu item is selected.
- *
- * Sends an HM_DISPLAY_HELP message to the help
- * instance so that the default Using Help is
- * displayed.
- *
- * API's : WinSendMsg
- *
- * Parameters : [none]
- *
- * Return : [none]
- *
- *************************************************************************/
- VOID HelpUsingHelp(VOID)
- {
- /* this just displays the system help for help panel */
- if(fHelpEnabled)
- if(NULL != WinSendMsg(hwndHelpInstance, HM_DISPLAY_HELP,
- (MPARAM)NULL, (MPARAM)NULL))
- MessageBox(hwndClient,
- IDMSG_HELPDISPLAYERROR,
- MB_OK | MB_ERROR,
- FALSE);
- } /* End of HelpUsingHelp */
-
-
- /**************************************************************************
- *
- * Name : HelpKeys()
- *
- * Description: Processes the WM_COMMAND message posted by the
- * Keys Help item of the Help menu.
- *
- * Concepts: Called from MainCommand when the Keys Help
- * menu item is selected.
- *
- * Sends an HM_KEYS_HELP message to the help
- * instance so that the default Keys Help is
- * displayed.
- *
- * API's : WinSendMsg
- *
- * Parameters : [none]
- *
- * Return : [none]
- *
- *************************************************************************/
- VOID HelpKeys(VOID)
- {
- /* this just displays the system keys help panel */
- if(fHelpEnabled)
- if(NULL != WinSendMsg(hwndHelpInstance, HM_KEYS_HELP,
- (MPARAM)NULL, (MPARAM)NULL))
- MessageBox(hwndClient,
- IDMSG_HELPDISPLAYERROR,
- MB_OK | MB_ERROR,
- FALSE);
- } /* End of HelpKeys */
-
-
- /**************************************************************************
- *
- * Name : HelpIndex()
- *
- * Description: Processes the WM_COMMAND message posted by the
- * Help Index item of the Help menu.
- *
- * Concepts: Called from MainCommand when the Help Index
- * menu item is selected.
- *
- * Sends an HM_INDEX_HELP message to the help
- * instance so that the default Help Index is
- * displayed.
- *
- * API's : WinSendMsg
- *
- * Parameters : [none]
- *
- * Return : [none]
- *
- *************************************************************************/
- VOID HelpIndex(VOID)
- {
- /* this just displays the system help index panel */
- if(fHelpEnabled)
- if(NULL != WinSendMsg(hwndHelpInstance, HM_HELP_INDEX,
- (MPARAM)NULL, (MPARAM)NULL))
- MessageBox(hwndClient,
- IDMSG_HELPDISPLAYERROR,
- MB_OK | MB_ERROR,
- FALSE);
- } /* End of HelpIndex() */
-
-
- /**************************************************************************
- *
- * Name : HelpTutorial()
- *
- * Description: Processes the WM_COMMAND message posted by the
- * Tutorial Help item of the Help menu. While the
- * standard template application does not include a
- * Tutorial menu item, you can add one if your
- * application has a tutorial.
- *
- * Concepts: Called from MainCommand when the Tutorial Help
- * menu item is selected.
- *
- * API's : WinLoadMessage
- * WinMessageBox
- * WinAlarm
- *
- * Parameters : [none]
- *
- * Return : [none]
- *
- *************************************************************************/
- VOID HelpTutorial(VOID)
- {
- CHAR szText[MESSAGELEN];
-
- /*
- * Insert code for any tutorial below in place of the message box.
- */
- if(!WinLoadMessage(hab,
- (HMODULE)NULLHANDLE,
- IDMSG_YOURTUTORIAL,
- MESSAGELEN,
- (PSZ)szText))
- {
- WinAlarm(HWND_DESKTOP, WA_ERROR);
- return;
- }
- WinMessageBox(HWND_DESKTOP,
- hwndClient,
- szText,
- "Tutorial",
- MB_OK | MB_INFORMATION,
- FALSE);
-
- } /* End of HelpTutorial */
-
-
-
- /**************************************************************************
- *
- * Name : DisplayHelpPanel(idPanel)
- *
- * Description: Displays the help panel whose id is given
- *
- * Concepts: Called whenever a help panel is desired to be
- * displayed, usually from the WM_HELP processing
- * of the dialog boxes.
- *
- * Sends HM_DISPLAY_HELP message to the help instance.
- *
- * API's : WinSendMsg
- *
- * Parameters : idPanel = panel i.d.
- *
- * Return : [none]
- *
- *************************************************************************/
- VOID DisplayHelpPanel(ULONG idPanel)
- {
- if(fHelpEnabled)
- if(NULL != WinSendMsg(hwndHelpInstance,
- HM_DISPLAY_HELP,
- MPFROMLONG(idPanel),
- MPFROMSHORT(HM_RESOURCEID)))
- MessageBox(hwndFrame,
- IDMSG_HELPDISPLAYERROR,
- MB_OK | MB_ERROR,
- TRUE);
- } /* End of DisplayHelpPanel */
-
-
- /**************************************************************************
- *
- * Name : DestroyHelpInstance()
- *
- * Description: Destroys the help instance for the application
- *
- * Concepts: Called after exit from message loop.
- *
- * Calls WinDestroyHelpInstance() to destroy the
- * help instance.
- *
- * API's : WinDestroyHelpInstance
- *
- * Parameters : [none]
- *
- * Return : [none]
- *
- *************************************************************************/
- VOID DestroyHelpInstance(VOID)
- {
- if(hwndHelpInstance != NULLHANDLE)
- WinDestroyHelpInstance(hwndHelpInstance);
- } /* End of DestroyHelpInstance */
- /*************************** End of help.c ****************************/