home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gpiimage.zip / IMG_HELP.C < prev    next >
C/C++ Source or Header  |  1998-04-20  |  11KB  |  340 lines

  1. /**************************************************************************
  2.  *  File name  :  img_help.c
  3.  *
  4.  *  Description:  This module contains all the routines for interfacing with
  5.  *                the IPF help manager.
  6.  *
  7.  *                HelpInit()
  8.  *                HelpUsingHelp()
  9.  *                HelpGeneral()
  10.  *                HelpIndex()
  11.  *                HelpProductInfo()
  12.  *                HelpDestroyInstance()
  13.  *
  14.  *  Concepts   :  online help
  15.  *
  16.  *  API's      :  WinLoadString
  17.  *                WinCreateHelpInstance
  18.  *                WinAssociateHelpInstance
  19.  *                WinSendMsg
  20.  *                WinDestroyHelpInstance
  21.  *                WinDlgBox
  22.  *
  23.  *  Required
  24.  *    Files    :  OS2.H, STRING.H, IMG_MAIN.H, IMG_XTRN.H, IMG_DLG.H,
  25.  *                   IMG_HELP.H
  26.  *
  27.  *  Copyright (C) 1991 IBM Corporation
  28.  *
  29.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  30.  *      sample code created by IBM Corporation. This sample code is not
  31.  *      part of any standard or IBM product and is provided to you solely
  32.  *      for  the purpose of assisting you in the development of your
  33.  *      applications.  The code is provided "AS IS", without
  34.  *      warranty of any kind.  IBM shall not be liable for any damages
  35.  *      arising out of your use of the sample code, even if they have been
  36.  *      advised of the possibility of such damages.                                                    *
  37.  *************************************************************************/
  38. /*
  39.  *  Include files, macros, defined constants, and externs
  40.  */
  41. #define INCL_WINHELP
  42. #define INCL_WINDIALOGS
  43. #define INCL_WINSTDFILE
  44.  
  45. #include <os2.h>
  46. #include <string.h>
  47.  
  48. #include "img_main.h"
  49. #include "img_xtrn.h"
  50. #include "img_dlg.h"
  51. #include "img_help.h"
  52.  
  53. #define HELPLIBRARYNAMELEN  20
  54.  
  55. /*
  56.  *  Global variables
  57.  */
  58. static HWND hwndHelpInstance;
  59.  
  60. #ifdef HELP_MANAGER_ENABLED
  61.  
  62. /**************************************************************************
  63.  *
  64.  *  Name       : HelpInit()
  65.  *
  66.  *  Description: Initializes the IPF help facility
  67.  *
  68.  *  Concepts   : Called once during initialization of the program
  69.  *
  70.  *               Initializes the HELPINIT structure and creates the
  71.  *               help instance.  If successful, the help instance
  72.  *               is associated with the main window.
  73.  *
  74.  *  API's      : WinLoadString
  75.  *               WinCreateHelpInstance
  76.  *               WinAssociateHelpInstance
  77.  *
  78.  *  Parameters : [none]
  79.  *
  80.  *  Return     : [none]
  81.  *
  82.  *************************************************************************/
  83. VOID HelpInit(VOID)
  84. {
  85.    HELPINIT hini;
  86.    CHAR szLibName[HELPLIBRARYNAMELEN];
  87.    CHAR szWindowTitle[HELPLIBRARYNAMELEN];
  88.  
  89.    /* inititalize help init structure */
  90.    hini.cb = sizeof(HELPINIT);
  91.    hini.ulReturnCode = 0;
  92.  
  93.    hini.pszTutorialName = (PSZ)NULL;   /* if tutorial added, add name here */
  94.  
  95.    hini.phtHelpTable = (PHELPTABLE)(0xFFFF0000 | IMAGE_HELP_TABLE);
  96.    hini.hmodHelpTableModule = 0;
  97.    hini.hmodAccelActionBarModule = 0;
  98.    hini.idAccelTable = 0;
  99.    hini.idActionBar = 0;
  100.  
  101. #if (defined(PORT_16) || defined(PORT_S116))
  102. #ifdef DEBUG
  103.    hini.usShowPanelId = CMIC_SHOW_PANEL_ID;
  104. #else
  105.    hini.usShowPanelId = CMIC_HIDE_PANEL_ID;
  106. #endif  /* DEBUG       */
  107. #else   /* NOT PORT_16 */
  108. #ifdef DEBUG
  109.    hini.fShowPanelId = CMIC_SHOW_PANEL_ID;
  110. #else
  111.    hini.fShowPanelId = CMIC_HIDE_PANEL_ID;
  112. #endif  /* DEBUG       */
  113. #endif  /* NOT PORT_16 */
  114.  
  115.    if (!WinLoadString(vhab,
  116.                       (HMODULE)0,
  117.                       IDS_HELPWINDOWTITLE,
  118.                       HELPLIBRARYNAMELEN,
  119.                       (PSZ)szWindowTitle))
  120.    {
  121.        MessageBox(vhwndFrame, IDMSG_CANNOTLOADSTRING, 0,
  122.                   MB_OK | MB_ERROR, FALSE);
  123.        return;
  124.    }
  125.    hini.pszHelpWindowTitle = (PSZ)szWindowTitle;
  126.  
  127.    if (!WinLoadString(vhab,
  128.                       (HMODULE)0,
  129.                       IDS_HELPLIBRARYNAME,
  130.                       HELPLIBRARYNAMELEN,
  131.                       (PSZ)szLibName))
  132.    {
  133.        MessageBox(vhwndFrame, IDMSG_CANNOTLOADSTRING, 0,
  134.                   MB_OK | MB_ERROR, FALSE);
  135.        return;
  136.    }
  137.    hini.pszHelpLibraryName = (PSZ)szLibName;
  138.  
  139.  
  140.    /* creating help instance */
  141.    hwndHelpInstance = WinCreateHelpInstance(vhab, &hini);
  142.  
  143.    if (!hwndHelpInstance || hini.ulReturnCode)
  144.    {
  145.        MessageBox(vhwndFrame, IDMSG_HELPLOADERROR, 0,
  146.                   MB_OK | MB_ERROR, FALSE);
  147.        return;
  148.    }
  149.  
  150.    /* associate help instance with main frame */
  151.    if (!WinAssociateHelpInstance(hwndHelpInstance, vhwndFrame))
  152.    {
  153.        MessageBox(vhwndFrame, IDMSG_HELPLOADERROR, 0,
  154.                   MB_OK | MB_ERROR, FALSE);
  155.        return;
  156.    }
  157.  
  158.    /* set flag to enable Help menu items */
  159.    vfHelpEnabled = TRUE;
  160. }   /* End of HelpInit */
  161.  
  162. /**************************************************************************
  163.  *
  164.  *  Name       : HelpUsingHelp()
  165.  *
  166.  *  Description: Processes the WM_COMMAND message posted by the
  167.  *               Using help item of the Help menu
  168.  *
  169.  *  Concepts   : Called from MainCommand when the Using help
  170.  *               menu item is selected
  171.  *
  172.  *               Sends an HM_DISPLAY_HELP message to the help
  173.  *               instance so that the default Using help is
  174.  *               displayed.
  175.  *
  176.  *  API's      : WinSendMsg
  177.  *
  178.  *  Parameters : [none]
  179.  *
  180.  *  Return     : [none]
  181.  *
  182.  *************************************************************************/
  183. VOID  HelpUsingHelp(VOID)
  184. {
  185.    /* this just displays the system help for help panel */
  186.    if (NULL != WinSendMsg(hwndHelpInstance, HM_DISPLAY_HELP,
  187.                           (MPARAM)NULL, (MPARAM)NULL))
  188.        MessageBox(vhwndFrame, IDMSG_HELPDISPLAYERROR, 0, MB_OK | MB_ERROR,
  189.                   FALSE);
  190. }   /* End of HelpUsingHelp   */
  191.  
  192. /**************************************************************************
  193.  *
  194.  *  Name       : HelpGeneral()
  195.  *
  196.  *  Description: Processes the WM_COMMAND message posted by the
  197.  *               General help item of the Help menu
  198.  *
  199.  *  Concepts   : Called from MainCommand when the General help
  200.  *               menu item is selected
  201.  *
  202.  *               Sends an HM_EXT_HELP message to the help
  203.  *               instance so that the default General help is
  204.  *               displayed.
  205.  *
  206.  *  API's      : WinSendMsg
  207.  *
  208.  *  Parameters : [none]
  209.  *
  210.  *  Return     : [none]
  211.  *
  212.  *************************************************************************/
  213. VOID HelpGeneral(VOID)
  214. {
  215.    /* this just displays the system general help panel */
  216.    if (NULL != WinSendMsg(hwndHelpInstance, HM_EXT_HELP,
  217.                           (MPARAM)NULL, (MPARAM)NULL))
  218.          MessageBox(vhwndFrame, IDMSG_HELPDISPLAYERROR, 0, MB_OK | MB_ERROR,
  219.                     FALSE);
  220. }   /* End of HelpGeneral() */
  221.  
  222. /**************************************************************************
  223.  *
  224.  *  Name       : HelpIndex()
  225.  *
  226.  *  Description: Processes the WM_COMMAND message posted by the
  227.  *               Help index item of the Help menu
  228.  *
  229.  *  Concepts   : Called from MainCommand when the Help index
  230.  *               menu item is selected
  231.  *
  232.  *               Sends an HM_INDEX_HELP message to the help
  233.  *               instance so that the Help Index is displayed.
  234.  *
  235.  *  API's      : WinSendMsg
  236.  *
  237.  *  Parameters : [none]
  238.  *
  239.  *  Return     : [none]
  240.  *
  241.  *************************************************************************/
  242. VOID HelpIndex(VOID)
  243. {
  244.     /* this just displays the system help index panel */
  245.    if (NULL != WinSendMsg(hwndHelpInstance, HM_HELP_INDEX,
  246.                           (MPARAM)NULL, (MPARAM)NULL))
  247.        MessageBox(vhwndFrame, IDMSG_HELPDISPLAYERROR, 0, MB_OK | MB_ERROR,
  248.                   FALSE);
  249. }   /* End of HelpIndex() */
  250.  
  251. /**************************************************************************
  252.  *
  253.  *  Name       : HelpDestroyInstance()
  254.  *
  255.  *  Description: Destroys the help instance for the application
  256.  *
  257.  *  Concepts   : Called during Exit list processing
  258.  *
  259.  *               Calls WinDestroyHelpInstance() to destroy the
  260.  *               help instance
  261.  *
  262.  *  API's      : WinDestroyHelpInstance
  263.  *
  264.  *  Parameters : [none]
  265.  *
  266.  *  Return     : [none]
  267.  *
  268.  *************************************************************************/
  269. VOID HelpDestroyInstance(VOID)
  270. {
  271.    if(hwndHelpInstance != 0L)
  272.    {
  273.       WinDestroyHelpInstance(hwndHelpInstance);
  274.    }
  275.    vfHelpEnabled = FALSE;
  276. }   /* End of HelpDestroyInstance */
  277.  
  278. #endif
  279.  
  280. /**************************************************************************
  281.  *
  282.  *  Name       : HelpProductInfo()
  283.  *
  284.  *  Description:  Processes the WM_COMMAND message posted by the
  285.  *                Product information item of the Help menu
  286.  *
  287.  *  Concepts   : Called from MainCommand when the Product information
  288.  *               menu item is selected
  289.  *
  290.  *               Calls WinDlgBox to display the Product information
  291.  *
  292.  *  API's      : WinDlgBox
  293.  *
  294.  *  Parameters : [none]
  295.  *
  296.  *  Return     : [none]
  297.  *
  298.  *************************************************************************/
  299. VOID  HelpProductInfo(void)
  300. {
  301.     WinDlgBox(HWND_DESKTOP, vhwndClient, ProductInfoDlgProc, (HMODULE)0,
  302.               IDD_PRODUCTINFO, (PVOID)NULL);
  303. }   /* End of HelpProductInfo */
  304.  
  305. /**************************************************************************
  306.  *
  307.  *  Name       : DisplayHelpPanel(idPanel)
  308.  *
  309.  *  Description:  Displays the help panel whose id is given
  310.  *
  311.  *  Concepts   : Called whenever a help panel is desired to be
  312.  *               displayed, usually from the WM_HELP processing
  313.  *               of the dialog boxes
  314.  *
  315.  *               Sends HM_DISPLAY_HELP message to the help instance
  316.  *
  317.  *  API's      : WinSendMsg
  318.  *
  319.  *  Parameters : idPanel = code number of the help panel to be displayed
  320.  *
  321.  *  Return     : [none]
  322.  *
  323.  *************************************************************************/
  324. VOID DisplayHelpPanel(ULONG idPanel)
  325. {
  326.    if(vfHelpEnabled)
  327.        if(NULL != WinSendMsg(hwndHelpInstance,
  328.                              HM_DISPLAY_HELP,
  329.                              MPFROMLONG(idPanel),
  330.                              MPFROMSHORT(HM_RESOURCEID)))
  331.    {
  332.            MessageBox(vhwndFrame,
  333.                       IDMSG_HELPDISPLAYERROR,
  334.                       0,
  335.                       MB_OK | MB_ERROR,
  336.                       TRUE);
  337.     }
  338. }   /* End of DisplayHelpPanel() */
  339. /***************************  End of img_help.c  *************************/
  340.