home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / os2 / semaph / sem_help.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  15KB  |  394 lines

  1. /*static char *SCCSID = "@(#)sem_help.c    6.17 92/02/19";*/
  2. /*==============================================================*\
  3.  *  SEM_HELP.C - routines for help information                  *
  4.  *      (C) Copyright IBM Corporation 1992.                     *
  5.  *--------------------------------------------------------------*
  6.  *                                                              *
  7.  *  This module contains all the routines for interfacing with  *
  8.  *  the IPF help manager.                                       *
  9.  *                                                              *
  10.  *--------------------------------------------------------------*
  11.  *                                                              *
  12.  *  This source file contains the following functions:          *
  13.  *                                                              *
  14.  *          InitHelp()                                          *
  15.  *          HelpHelpForHelp(mp2)                                *
  16.  *          HelpExtended(mp2)                                   *
  17.  *          HelpKeys(mp2)                                       *
  18.  *          HelpIndex(mp2)                                      *
  19.  *          HelpAbout(mp2)                                      *
  20.  *          DisplayHelpPanel(idPanel)                           *
  21.  *          DestroyHelpInstance(VOID)                           *
  22.  *          AboutDlgProc(hwnd, msg, mp1, mp2)                   *
  23.  *          FixSysMenu(hwndDlg)                                 *
  24.  *                                                              *
  25. \*==============================================================*/
  26.  
  27. /*--------------------------------------------------------------*\
  28.  *  Include files, macros, defined constants, and externs       *
  29. \*--------------------------------------------------------------*/
  30. #include "semaph.h"
  31.  
  32. /****************************************************************\
  33.  *  Routine for initializing the help manager
  34.  *--------------------------------------------------------------
  35.  *
  36.  *  Name:    InitHelp()
  37.  *
  38.  *  Purpose: Initializes the IPF help facility
  39.  *
  40.  *  Usage:   Called once during initialization of the program
  41.  *
  42.  *  Method:  Initializes the HELPINIT structure and creates the help
  43.  *           instance. If successful, the help instance is associated
  44.  *           with the main window
  45.  *
  46.  *  Returns: VOID
  47.  *
  48. \****************************************************************/
  49. VOID InitHelp(VOID)
  50. {
  51.    HELPINIT hini;
  52.  
  53.     /* If we return because of an error, Help will be disabled */
  54.    fHelpEnabled = FALSE;
  55.                              /* Initialize help init structure */
  56.    hini.cb = sizeof(HELPINIT);
  57.    hini.ulReturnCode = 0;
  58.                            /* If tutorial added, add name here */
  59.    hini.pszTutorialName = (PSZ)NULL;
  60.  
  61.    hini.phtHelpTable = (PHELPTABLE)MAKELONG(SEMAPH_HELP_TABLE, 0xFFFF);
  62.    hini.hmodHelpTableModule = 0;
  63.    hini.hmodAccelActionBarModule = 0;
  64.    hini.idAccelTable = 0;
  65.    hini.idActionBar = 0;
  66.  
  67.    if(!WinLoadString(hab,
  68.                      0,
  69.                      IDS_HELPWINDOWTITLE,
  70.                      HELPLIBRARYNAMELEN,
  71.                      (PSZ)szWindowTitle))
  72.    {
  73.        MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING,TRUE);
  74.        return;
  75.    }
  76.    hini.pszHelpWindowTitle = (PSZ)szWindowTitle;
  77.  
  78.                    /* If debugging, show panel ids, else don't */
  79. #ifdef DEBUG
  80.    hini.fShowPanelId = CMIC_SHOW_PANEL_ID;
  81. #else
  82.    hini.fShowPanelId = CMIC_HIDE_PANEL_ID;
  83. #endif
  84.  
  85.    if(!WinLoadString(hab,
  86.                      0,
  87.                      IDS_HELPLIBRARYNAME,
  88.                      HELPLIBRARYNAMELEN,
  89.                      (PSZ)szLibName))
  90.    {
  91.        MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING,TRUE);
  92.        return;
  93.    }
  94.    hini.pszHelpLibraryName = (PSZ)szLibName;
  95.                                      /* Creating help instance */
  96.    hwndHelpInstance = WinCreateHelpInstance(hab, &hini);
  97.  
  98.    if(hwndHelpInstance == 0 || hini.ulReturnCode)
  99.    {
  100.        MessageBox(hwndMainFrame, IDMSG_HELPLOADERROR,TRUE);
  101.        return;
  102.    }
  103.                     /* Associate help instance with main frame */
  104.    if(!WinAssociateHelpInstance(hwndHelpInstance, hwndMainFrame))
  105.    {
  106.        MessageBox(hwndMainFrame, IDMSG_HELPLOADERROR,TRUE);
  107.        return;
  108.    }
  109. /* Help manager is successfully initialized so set flag to TRUE */
  110.    fHelpEnabled = TRUE;
  111.    return;
  112. }                                                 /* InitHelp() */
  113.  
  114. /****************************************************************\
  115.  *  Processes the Help for Help command from the menu bar
  116.  *--------------------------------------------------------------
  117.  *
  118.  *  Name:    HelpHelpForHelp(mp2)
  119.  *
  120.  *  Purpose: Processes the WM_COMMAND message posted by the Help for
  121.  *           Help item of the Help menu
  122.  *
  123.  *  Usage:   Called from MainCommand when the Help for Help menu item
  124.  *           is selected
  125.  *
  126.  *  Method:  Sends an HM_DISPLAY_HELP message to the help instance so
  127.  *           that the default Help For Help is displayed.
  128.  *
  129.  *  Returns: VOID
  130.  *
  131. \****************************************************************/
  132. VOID HelpHelpForHelp(MPARAM mp2)
  133. {
  134.           /* This just displays the system help for help panel */
  135.    if(fHelpEnabled)
  136.      if((LONG)WinSendMsg(hwndHelpInstance,HM_DISPLAY_HELP,
  137.                                  (MPARAM)0,(MPARAM)0))
  138.            MessageBox(hwndMain, IDMSG_HELPDISPLAYERROR,TRUE);
  139.  
  140.    /* This routine currently doesn't use the mp2 parameter but     *\
  141.     *  it is referenced here to prevent an 'Unreferenced Parameter'*
  142.    \*  warning at compile time.                                    */
  143.    return;
  144. }                                          /* HelpHelpForHelp() */
  145.  
  146. /****************************************************************\
  147.  *  Processes the Extended Help command from the menu bar
  148.  *--------------------------------------------------------------
  149.  *
  150.  *  Name:    HelpExtended(mp2)
  151.  *
  152.  *  Purpose: Processes the WM_COMMAND message posted by the Extended
  153.  *           Help item of the Help menu.
  154.  *
  155.  *  Usage:   Called from MainCommand when the Extended Help menu item
  156.  *           is selected.
  157.  *
  158.  *  Method:  Sends an HM_EXT_HELP message to the help instance so that
  159.  *           the default Extended Help is displayed.
  160.  *
  161.  *  Returns: VOID
  162.  *
  163. \****************************************************************/
  164. VOID HelpExtended(MPARAM mp2)
  165. {
  166.           /* This just displays the system extended help panel */
  167.    if(fHelpEnabled)
  168.      if((LONG)WinSendMsg(hwndHelpInstance,HM_EXT_HELP,(MPARAM)0L,(MPARAM)0L))
  169.            MessageBox(hwndMain, IDMSG_HELPDISPLAYERROR,TRUE);
  170.  
  171.    /* This routine currently doesn't use the mp2 parameter but     *\
  172.     *  it is referenced here to prevent an 'Unreferenced Parameter'*
  173.    \*  warning at compile time.                                    */
  174.    return;
  175. }                                             /* HelpExtended() */
  176.  
  177. /****************************************************************\
  178.  *  Processes the Keys Help command from the menu bar
  179.  *--------------------------------------------------------------
  180.  *
  181.  *  Name:    HelpKeys(mp2)
  182.  *
  183.  *  Purpose: Processes the WM_COMMAND message posted by the Keys Help
  184.  *           item of the Help menu.
  185.  *
  186.  *  Usage:   Called from MainCommand when the Keys Help menu item is
  187.  *           selected
  188.  *
  189.  *  Method:  Sends an HM_KEYS_HELP message to the help instance so that
  190.  *           the default Keys Help is displayed.
  191.  *
  192.  *  Returns: VOID
  193.  *
  194. \****************************************************************/
  195. VOID HelpKeys(MPARAM mp2)
  196. {
  197.               /* This just displays the system keys help panel */
  198.    if(fHelpEnabled)
  199.      if((LONG)WinSendMsg(hwndHelpInstance,HM_KEYS_HELP,(MPARAM)0L,(MPARAM)0L))
  200.           MessageBox(hwndMain, IDMSG_HELPDISPLAYERROR,TRUE);
  201.  
  202.    /* This routine currently doesn't use the mp2 parameter but     *\
  203.     *  it is referenced here to prevent an 'Unreferenced Parameter'*
  204.    \*  warning at compile time.                                    */
  205.    return;
  206. }                                                 /* HelpKeys() */
  207.  
  208. /****************************************************************\
  209.  *  Processes the Index Help command from the menu bar
  210.  *--------------------------------------------------------------
  211.  *
  212.  *  Name:    HelpIndex(mp2)
  213.  *
  214.  *  Purpose: Processes the WM_COMMAND message posted by the Index Help
  215.  *           item of the Help menu
  216.  *
  217.  *  Usage:   Called from MainCommand when the Index Help menu item
  218.  *           is selected
  219.  *
  220.  *  Method:  Sends an HM_INDEX_HELP message to the help instance so
  221.  *           that the default Index Help is displayed.
  222.  *
  223.  *
  224.  *  Returns: VOID
  225.  *
  226. \****************************************************************/
  227. VOID HelpIndex(MPARAM mp2)
  228. {
  229.              /* This just displays the system help index panel */
  230.    if(fHelpEnabled)
  231.      if((LONG)WinSendMsg(hwndHelpInstance,HM_HELP_INDEX,(MPARAM)0L,(MPARAM)0L))
  232.            MessageBox(hwndMain, IDMSG_HELPDISPLAYERROR,TRUE);
  233.  
  234.    /* This routine currently doesn't use the mp2 parameter but     *\
  235.     *  it is referenced here to prevent an 'Unreferenced Parameter'*
  236.    \*  warning at compile time.                                    */
  237.    return;
  238. }                                                /* HelpIndex() */
  239.  
  240. /****************************************************************\
  241.  *  Processes the About command from the Help menu
  242.  *--------------------------------------------------------------
  243.  *
  244.  *  Name:    HelpAbout(mp2)
  245.  *
  246.  *  Purpose: Processes the WM_COMMAND message posted by the About item
  247.  *           of the Help menu
  248.  *
  249.  *  Usage:   Called from MainCommand when the About menu item is selected
  250.  *
  251.  *  Method:  Calls WinDlgBox to display the about box dialog.
  252.  *
  253.  *  Returns: VOID
  254.  *
  255. \****************************************************************/
  256. VOID HelpAbout(MPARAM mp2)
  257. {
  258.                                 /* Display the AboutBox dialog */
  259.    WinDlgBox(HWND_DESKTOP,
  260.              hwndMain,
  261.              AboutDlgProc,
  262.              (HMODULE)0,
  263.              IDD_PRODUCTINFO,
  264.              NULL);
  265.  
  266.    /* This routine currently doesn't use the mp2 parameter but     *\
  267.     *  it is referenced here to prevent an 'Unreferenced Parameter'*
  268.    \*  warning at compile time.                                    */
  269.    return;
  270. }                                                /* HelpAbout() */
  271.  
  272. /****************************************************************\
  273.  *  Displays the help panel indicated
  274.  *--------------------------------------------------------------
  275.  *
  276.  *  Name:    DisplayHelpPanel(idPanel)
  277.  *
  278.  *  Purpose: Displays the help panel whose id is given
  279.  *
  280.  *  Usage:   Called whenever a help panel is desired to be displayed,
  281.  *           usually from the WM_HELP processing of the dialog boxes
  282.  *
  283.  *  Method:  Sends HM_DISPLAY_HELP message to the help instance
  284.  *
  285.  *  Returns: VOID
  286.  *
  287. \****************************************************************/
  288. VOID DisplayHelpPanel(LONG idPanel)
  289. {
  290.    if(fHelpEnabled)
  291.        if((LONG)WinSendMsg(hwndHelpInstance,
  292.                      HM_DISPLAY_HELP,
  293.                      MPFROMLONG(MAKELONG(idPanel, NULL)),
  294.                      MPFROMSHORT(HM_RESOURCEID)))
  295.  
  296.            MessageBox(hwndMainFrame, IDMSG_HELPDISPLAYERROR, TRUE);
  297.    return;
  298. }                                         /* DisplayHelpPanel() */
  299.  
  300. /****************************************************************\
  301.  *  Destroys the help instance
  302.  *--------------------------------------------------------------
  303.  *
  304.  *  Name:    DestroyHelpInstance(VOID)
  305.  *
  306.  *  Purpose: Destroys the help instance for the application
  307.  *
  308.  *  Usage:   Called after exit from message loop
  309.  *
  310.  *  Method:  Calls WinDestroyHelpInstance() to destroy the help instance
  311.  *
  312.  *  Returns: VOID
  313.  *
  314. \****************************************************************/
  315. VOID DestroyHelpInstance(VOID)
  316. {
  317.    if(hwndHelpInstance != 0)
  318.    {
  319.       WinDestroyHelpInstance(hwndHelpInstance);
  320.    }
  321.    return;
  322. }                                      /* DestroyHelpInstance() */
  323.  
  324. /****************************************************************\
  325.  *
  326.  * Name:    AboutDlgProc(hwnd, msg, mp1, mp2)
  327.  *
  328.  * Purpose: Handles all the messages associated with the About dialog.
  329.  *
  330.  * Usage:   Called from HelpAbout() when about menu be selected.
  331.  *
  332.  * Returns:
  333.  *
  334. \****************************************************************/
  335. MRESULT EXPENTRY AboutDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  336. {
  337.    MRESULT sRC;
  338.  
  339.    switch(msg)
  340.    {
  341.       case WM_INITDLG:
  342.          FixSysMenu(hwnd);
  343.          return (MRESULT)0L;
  344.  
  345.       case WM_COMMAND:
  346.          WinDismissDlg(hwnd, TRUE);
  347.          return (MRESULT)0L;
  348.  
  349.       default:
  350.          sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  351.          return sRC;
  352.    }
  353.    return 0L;
  354. }
  355.  
  356. /****************************************************************\
  357.  * Name:    FixSysMenu()                                         *
  358.  *                                                               *
  359.  * Purpose: This routine removes the Restore, Size, Minimize, and*
  360.  *          Maximize options from the system menu of a dialog.   *
  361.  *                                                               *
  362.  * Usage  : Called during the WM_INITDLG of a dialog procedure.  *
  363.  *                                                               *
  364.  * Returns: VOID                                                 *
  365.  *                                                               *
  366. \****************************************************************/
  367. VOID FixSysMenu(HWND hwndDlg)
  368. {
  369.    HWND hwndMenu;                                   /* handle to system menu */
  370.  
  371.    hwndMenu = WinWindowFromID(hwndDlg, FID_SYSMENU);
  372.  
  373.    WinSendMsg(hwndMenu,               /* delete Restore from the system menu */
  374.               MM_DELETEITEM,
  375.               MPFROM2SHORT(SC_RESTORE, TRUE),
  376.               MPFROMP(NULL));
  377.  
  378.    WinSendMsg(hwndMenu,                  /* delete Size from the system menu */
  379.               MM_DELETEITEM,
  380.               MPFROM2SHORT(SC_SIZE, TRUE),
  381.               MPFROMP(NULL));
  382.  
  383.    WinSendMsg(hwndMenu,              /* delete Minimize from the system menu */
  384.               MM_DELETEITEM,
  385.               MPFROM2SHORT(SC_MINIMIZE, TRUE),
  386.               MPFROMP(NULL));
  387.  
  388.    WinSendMsg(hwndMenu,              /* delete Maximize from the system menu */
  389.               MM_DELETEITEM,
  390.               MPFROM2SHORT(SC_MAXIMIZE, TRUE),
  391.               MPFROMP(NULL));
  392.    return;
  393. }
  394.