home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / source / devnews / vol2 / sample3 / sty_help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-29  |  11.8 KB  |  362 lines

  1. /*************************************************************************
  2. *
  3. *  File Name   : STY_HELP.C
  4. *
  5. *  Description : This module contains all the routines for
  6. *                interfacing with the IPF help manager.
  7. *
  8. *  Concepts    : Help initialization and termination, handling of
  9. *                help menu items.
  10. *
  11. *  API's       : WinCreateHelpInstance
  12. *                WinAssociateHelpInstance
  13. *                WinLoadString
  14. *                WinSendMsg
  15. *                WinDlgBox
  16. *                WinDestroyHelpInstance
  17. *
  18. *  Copyright (C) 1992 IBM Corporation
  19. *
  20. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  21. *      sample code created by IBM Corporation. This sample code is not
  22. *      part of any standard or IBM product and is provided to you solely
  23. *      for  the purpose of assisting you in the development of your
  24. *      applications.  The code is provided "AS IS", without
  25. *      warranty of any kind.  IBM shall not be liable for any damages
  26. *      arising out of your use of the sample code, even if they have been
  27. *      advised of the possibility of such damages.                                                    *
  28. *
  29. ************************************************************************/
  30.  
  31. /*  Include files, macros, defined constants, and externs       */
  32.  
  33. #define  INCL_WINHELP
  34.  
  35. #include <os2.h>
  36. #include <string.h>
  37. #include "sty_main.h"
  38. #include "sty_xtrn.h"
  39. #include "sty_dlg.h"
  40. #include "sty_help.h"
  41.  
  42. #define HELPLIBRARYNAMELEN  20
  43.  
  44. /*  Global variables                                            */
  45. static HWND hwndHelpInstance;
  46. static CHAR szLibName[HELPLIBRARYNAMELEN];
  47. static CHAR szWindowTitle[HELPLIBRARYNAMELEN];
  48.  
  49.  
  50. /*  Entry point declarations                                    */
  51. MRESULT EXPENTRY ProdInfoDlgProc(HWND hwnd, USHORT msg,
  52.                                  MPARAM mp1, MPARAM mp2);
  53.  
  54. /***************************************************************
  55.  *  Name: InitHelp
  56.  *
  57.  *  Description : Initializes the IPF help facility
  58.  *
  59.  *  Concepts : Initializes the HELPINIT structure and creates the
  60.  *             help instance.  If successful, the help instance
  61.  *             is associated with the main window
  62.  *
  63.  *  API's : WinCreateHelpInstance
  64.  *          WinAssociateHelpInstance
  65.  *          WinLoadString
  66.  *
  67.  *  Parameters : None
  68.  *
  69.  *  Returns:  None
  70.  *
  71.  ****************************************************************/
  72. VOID InitHelp(VOID)
  73. {
  74.   HELPINIT helpInit;
  75.  
  76.   /* if we return because of an error, Help will be disabled                */
  77.   fHelpEnabled = FALSE;
  78.  
  79.   /* inititalize help init structure                                        */
  80.   helpInit.cb = sizeof(HELPINIT);
  81.   helpInit.ulReturnCode = 0L;
  82.  
  83.   helpInit.pszTutorialName = (PSZ)NULL;   /* if tutorial added,             */
  84.                                           /* add name here                  */
  85.   helpInit.phtHelpTable = (PHELPTABLE)MAKELONG(STYLE_HELP_TABLE,
  86.                            0xFFFF);
  87.   helpInit.hmodHelpTableModule = (HMODULE)0;
  88.   helpInit.hmodAccelActionBarModule = (HMODULE)0;
  89.   helpInit.idAccelTable = 0;
  90.   helpInit.idActionBar = 0;
  91.  
  92.   if (!WinLoadString(hab, (HMODULE)0, IDS_HELPWINDOWTITLE,
  93.                     HELPLIBRARYNAMELEN, (PSZ)szWindowTitle))
  94.   {
  95.      MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  96.      return;
  97.   }
  98.   helpInit.pszHelpWindowTitle = (PSZ)szWindowTitle;
  99.   helpInit.fShowPanelId = CMIC_HIDE_PANEL_ID;
  100.  
  101.   if (!WinLoadString(hab, (HMODULE)0, IDS_HELPLIBRARYNAME,
  102.        HELPLIBRARYNAMELEN, (PSZ)szLibName))
  103.   {
  104.      MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  105.      return;
  106.   }
  107.  
  108.   helpInit.pszHelpLibraryName = (PSZ)szLibName;
  109.  
  110.   /* creating help instance                                                 */
  111.   hwndHelpInstance = WinCreateHelpInstance(hab, &helpInit);
  112.  
  113.   if (!hwndHelpInstance || helpInit.ulReturnCode)
  114.   {
  115.      MessageBox(hwndMainFrame, IDMSG_HELPLOADERROR, MB_OK | MB_ERROR, TRUE);
  116.      return;
  117.   }
  118.  
  119.   /* associate help instance with main frame                                */
  120.   if (!WinAssociateHelpInstance(hwndHelpInstance, hwndMainFrame))
  121.   {
  122.      MessageBox(hwndMainFrame, IDMSG_HELPLOADERROR, MB_OK | MB_ERROR, TRUE);
  123.      return;
  124.   }
  125.  
  126.   /* help manager is successfully initialized so set flag to TRUE           */
  127.   fHelpEnabled = TRUE;
  128.  
  129. }   /*                                          End of InitHelp()           */
  130.  
  131. /*********************************************************************
  132.  *  Name: HelpUsingHelp
  133.  *
  134.  *  Description : Processes the WM_COMMAND message posted
  135.  *                by the Using Help item of the Help menu
  136.  *
  137.  *  Concepts : Called from MainCommand when the Using Help menu item
  138.  *             is selected.  Sends an HM_DISPLAY_HELP message to the
  139.  *             help instance so that the default Using Help is
  140.  *             displayed.
  141.  *
  142.  *  API's : WinSendMsg
  143.  *
  144.  *  Parameters :  mp2 - Message parameter 2
  145.  *
  146.  *  Returns: None
  147.  *
  148.  ****************************************************************/
  149. VOID  HelpUsingHelp(MPARAM mp2)
  150. {
  151. /*    this just displays the system help for help panel                       */
  152.   if (fHelpEnabled)
  153.   {
  154.     if ((BOOL)WinSendMsg(hwndHelpInstance, HM_DISPLAY_HELP, NULL, NULL))
  155.     {
  156.        MessageBox(hwndMain, IDMSG_HELPDISPLAYERROR, MB_OK | MB_ERROR, FALSE);
  157.     }
  158.   }
  159.  /*
  160.   * This routine currently doesn't use the mp2 parameter but
  161.   * it is referenced here to prevent an 'Unreferenced Parameter'
  162.   * warning at compile time.
  163.   */
  164.   mp2;
  165. }   /* End of HelpUsingHelp()                                                */
  166.  
  167. /*********************************************************************
  168.  
  169.  *  Name: HelpUsingHelp
  170.  *
  171.  *  Description : Processes the WM_COMMAND message posted
  172.  *                by the General Help item of the Help menu
  173.  *
  174.  *  Concepts : Called from MainCommand when the General Help menu item
  175.  *             is selected.  Sends an HM_EXT_HELP message to the
  176.  *             help instance so that the default Extended Help is
  177.  *             displayed.
  178.  *
  179.  *  API's : WinSendMsg
  180.  *
  181.  *  Parameters :  mp2 - Message parameter 2
  182.  *
  183.  
  184.  *  Returns: None
  185.  *
  186.  ****************************************************************/
  187. VOID  HelpGeneral(MPARAM mp2)
  188. {
  189. /*   this just displays the system General help panel                       */
  190.    if (fHelpEnabled)
  191.    {
  192.      if ((BOOL)WinSendMsg(hwndHelpInstance, HM_EXT_HELP, NULL, NULL))
  193.      {
  194.         MessageBox(hwndMain, IDMSG_HELPDISPLAYERROR, MB_OK | MB_ERROR, FALSE);
  195.      }
  196.    }
  197.    /*
  198.     * This routine currently doesn't use the mp2 parameter but
  199.     * it is referenced here to prevent an 'Unreferenced Parameter'
  200.     * warning at compile time.
  201.     */
  202.     mp2;
  203.  
  204. }       /* End of HelpGeneral()                                      */
  205.  
  206. /*********************************************************************
  207.  *  Name: HelpKeys
  208.  *
  209.  *  Description : Processes the WM_COMMAND message posted
  210.  *                by the Keys Help item of the Help menu
  211.  *
  212.  *  Concepts : Called from MainCommand when the Keys Help menu item
  213.  *             is selected.  Sends an HM_KEYS_HELP message to the
  214.  *             help instance so that the default Extended Help is
  215.  *             displayed.
  216.  *
  217.  *  API's : WinSendMsg
  218.  *
  219.  *  Parameters :  mp2 - Message parameter 2
  220.  *
  221.  *  Returns: None
  222.  *
  223.  ****************************************************************/
  224. VOID  HelpKeys(MPARAM mp2)
  225. {
  226. /* this just displays the system keys help panel                              */
  227.   if (fHelpEnabled)
  228.   {
  229.     if ((BOOL)WinSendMsg(hwndHelpInstance, HM_KEYS_HELP, NULL, NULL))
  230.     {
  231.       MessageBox(hwndMain, IDMSG_HELPDISPLAYERROR, MB_OK | MB_ERROR, FALSE);
  232.     }
  233.   }
  234. /*
  235.  * This routine currently doesn't use the mp2 parameter but
  236.  * it is referenced here to prevent an 'Unreferenced Parameter'
  237.  * warning at compile time.
  238.  */
  239.   mp2;
  240. }   /*   End of HelpKeys()                                                    */
  241.  
  242. /*********************************************************************
  243.  *  Name: HelpIndex
  244.  *
  245.  *  Description : Processes the WM_COMMAND message posted
  246.  *                by the Index Help item of the Help menu
  247.  *
  248.  *  Concepts : Called from MainCommand when the Index Help menu item
  249.  *             is selected.  Sends an HM_INDEX_HELP message to the
  250.  *             help instance so that the default Extended Help is
  251.  *             displayed.
  252.  *
  253.  *  API's : WinSendMsg
  254.  *
  255.  *  Parameters :  mp2 - Message parameter 2
  256.  *
  257.  *  Returns: None
  258.  *
  259.  ****************************************************************/
  260. VOID  HelpIndex(MPARAM mp2)
  261. {
  262. /* this just displays the system help index panel                             */
  263.   if (fHelpEnabled)
  264.   {
  265.     if ((BOOL)WinSendMsg(hwndHelpInstance, HM_HELP_INDEX, NULL, NULL))
  266.     {
  267.        MessageBox(hwndMain, IDMSG_HELPDISPLAYERROR, MB_OK | MB_ERROR, FALSE);
  268.     }
  269.   }
  270.  /*
  271.   * This routine currently doesn't use the mp2 parameter but
  272.   * it is referenced here to prevent an 'Unreferenced Parameter'
  273.   * warning at compile time.
  274.  
  275.   */
  276.   mp2;
  277. }   /* End of HelpIndex()                                                     */
  278.  
  279. /*********************************************************************
  280.  *  Name: HelpProdInfo
  281.  *
  282.  *  Description : Processes the WM_COMMAND message posted
  283.  *                by the Index Help item of the Help menu
  284.  *
  285.  *  Concepts : Called from MainCommand when the Product
  286.  *             information Help menu item is selected.
  287.  *             Calls WinDlgBox to display the Product
  288.  *             Information dialog.
  289.  *
  290.  *  API's : WinDlgBox
  291.  *
  292.  *  Parameters :  mp2 - Message parameter 2
  293.  *
  294.  *  Returns: None
  295.  *
  296.  ****************************************************************/
  297. VOID  HelpProdInfo( MPARAM mp2)
  298. {
  299. /* display the Product Information dialog                                     */
  300.   WinDlgBox(HWND_DESKTOP, hwndMain, (PFNWP)ProdInfoDlgProc, (HMODULE)0,
  301.             IDD_PRODINFO, (PVOID)NULL);
  302.  /*
  303.  
  304.   * This routine currently doesn't use the mp2 parameter but
  305.   * it is referenced here to prevent an 'Unreferenced Parameter'
  306.   * warning at compile time.
  307.   */
  308.     mp2;
  309.  
  310. }   /* End of HelpProdInfo()                                                  */
  311.  
  312. /*********************************************************************
  313.  *  Name: DisplayHelp
  314.  *
  315.  *  Description : Displays the help panel indicated
  316.  *
  317.  *  Concepts : Displays the help panel whose id is passed to
  318.  *             the routine.  Called whenever a help panel is
  319.  *             desired to be displayed, usually from the
  320.  *             WM_HELP processing of the dialog boxes.
  321.  *
  322.  *  API's : WinSendMsg
  323.  *
  324.  *  Parameters : idPanel - Id of the halp panel to be displayed
  325.  *
  326.  *  Returns: None
  327.  *
  328.  ****************************************************************/
  329. VOID DisplayHelpPanel(SHORT idPanel)
  330. {
  331.   if (fHelpEnabled)
  332.   {
  333.     if ((BOOL)WinSendMsg(hwndHelpInstance, HM_DISPLAY_HELP,
  334.             MPFROM2SHORT(idPanel, NULL), MPFROMSHORT(HM_RESOURCEID)))
  335.     {
  336.       MessageBox(hwndMainFrame, IDMSG_HELPDISPLAYERROR,
  337.                  MB_OK | MB_ERROR, TRUE);
  338.     }
  339.   }
  340. }   /*    End of DisplayHelpPanel()                                   */
  341.  
  342. /*********************************************************************
  343.  *  Name: DestroyHelpInstance
  344.  *
  345.  *  Description : Destroys the help instance for the application
  346.  *
  347.  *  Concepts : Called after exit from message loop. Calls
  348.  
  349.  *             WinDestroyHelpInstance() to destroy the
  350.  *             help instance.
  351.  *
  352.  *  API's : WinDestroyHelpInstance
  353.  *
  354.  *  Parameters : None
  355.  
  356.  * None
  357.  *  Returns:
  358.  *
  359.  ****************************************************************/
  360. VOID DestroyHelpInstance(VOID)
  361. {
  362.   if ((BOOL)hwndHelpInstance)
  363.   {
  364.      WinDestroyHelpInstance(hwndHelpInstance);
  365.   }
  366.  
  367. }   /*        End of DestroyHelpInstance()                                    */
  368.