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

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