home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / pm / dragdrop / draghelp.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  14KB  |  417 lines

  1. /**************************************************************************
  2.  *  File name  :  draghelp.c
  3.  *
  4.  *  Description:  This file contains all the routines for interfacing
  5.  *                with the IPF help manager.
  6.  *
  7.  *                This source file contains the following functions:
  8.  *
  9.  *                InitHelp(hab, hwnd)
  10.  *                HelpUsingHelp(hwnd)
  11.  *                HelpGeneral(hwnd)
  12.  *                HelpIndex(hwnd)
  13.  *                HelpProductInfo(hwnd)
  14.  *                DestroyHelpInstance(hwnd)
  15.  *                ProductInfoDlgProc(hwnd, msg, mp1, mp2)
  16.  *                SetSysMenu(hwnd)
  17.  *
  18.  *  Concepts   :  IPF Help Manager
  19.  *
  20.  *  API's      :  WinLoadString
  21.  *                WinCreateHelpInstance
  22.  *                WinAssociateHelpInstance
  23.  *                WinSendMsg
  24.  *                WinDlgBox
  25.  *                WinDestroyHelpInstance
  26.  *                WinDefDlgProc
  27.  *                WinWindowFromID
  28.  *
  29.  *  Required
  30.  *    Files    :  OS2.H, STRING.H, STDIO.H, DRAGDROP.H, DRAGHELP.H
  31.  *
  32.  *  Copyright (C) 1991 IBM Corporation
  33.  *
  34.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  35.  *      sample code created by IBM Corporation. This sample code is not
  36.  *      part of any standard or IBM product and is provided to you solely
  37.  *      for  the purpose of assisting you in the development of your
  38.  *      applications.  The code is provided "AS IS", without
  39.  *      warranty of any kind.  IBM shall not be liable for any damages
  40.  *      arising out of your use of the sample code, even if they have been
  41.  *      advised of the possibility of such damages.                                                    *
  42.  *************************************************************************/
  43. /*
  44.  *  Include files, macros, defined constants, and externs
  45.  */
  46.  
  47. #define  INCL_WINHELP
  48. #define  INCL_WINSTDDRAG
  49. #define  INCL_WINMENUS
  50. #define  INCL_WINFRAMEMGR
  51.  
  52. #include <os2.h>
  53. #include <string.h>
  54. #include <stdio.h>
  55. #include "dragdrop.h"
  56. #include "draghelp.h"
  57.  
  58. #define HELPLIBRARYNAMELEN  20
  59.  
  60. /*
  61.  *  Global variables
  62.  */
  63. static HWND hwndHelpInstance;
  64. static CHAR szLibName[HELPLIBRARYNAMELEN];
  65. static CHAR szWindowTitle[HELPLIBRARYNAMELEN];
  66. static BOOL fHelpEnabled;
  67.  
  68. /*
  69.  *  Entry point declarations
  70.  */
  71. MRESULT EXPENTRY ProductInfoDlgProc(HWND hwnd,
  72.                                     USHORT msg,
  73.                                     MPARAM mp1,
  74.                                     MPARAM mp2);
  75.  
  76. /**************************************************************************
  77.  *
  78.  *  Name       :  InitHelp(hab, hwnd)
  79.  *
  80.  *  Description: Initializes the IPF help facility
  81.  *               Called once during initialization of the program
  82.  *
  83.  *  Concepts   : Initializes the HELPINIT structure and creates the
  84.  *               help instance.  If successful, the help instance
  85.  *               is associated with the main window queue
  86.  *
  87.  *  API's      :   WinLoadString
  88.  *                 WinCreateHelpInstance
  89.  *                 WinAssociateHelpInstance
  90.  *
  91.  *  Parameters :  hab      = anchor block handle
  92.  *                hwndMain = main window handle
  93.  *
  94.  *  Return     :  [none]
  95.  *
  96.  *************************************************************************/
  97. VOID InitHelp(HAB hab, HWND hwndMain)
  98. {
  99.    HELPINIT hini;
  100.  
  101.    /* If we return because of an error, Help will be disabled. */
  102.    fHelpEnabled = FALSE;
  103.  
  104.    /* initialize help init structure */
  105.    hini.cb = sizeof(HELPINIT);
  106.    hini.ulReturnCode = 0L;
  107.    hini.pszTutorialName = (PSZ)NULL;
  108.    hini.phtHelpTable = (PHELPTABLE)MAKELONG(DRAGDROP_HELP_TABLE, 0xFFFF);
  109.    hini.hmodHelpTableModule = 0;
  110.    hini.hmodAccelActionBarModule = 0;
  111.    hini.idAccelTable = 0;
  112.    hini.idActionBar = 0;
  113.  
  114.    if(!WinLoadString(hab,
  115.                      0,
  116.                      IDS_CLIENTCLASS,
  117.                      HELPLIBRARYNAMELEN,
  118.                      (PSZ)szWindowTitle))
  119.    {
  120.        MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  121.        return;
  122.    }
  123.  
  124.    hini.pszHelpWindowTitle = (PSZ)szWindowTitle;
  125.    hini.fShowPanelId = CMIC_HIDE_PANEL_ID;
  126.  
  127.    if(!WinLoadString(hab,
  128.                      0,
  129.                      IDS_HELPLIBRARYNAME,
  130.                      HELPLIBRARYNAMELEN,
  131.                      (PSZ)szLibName))
  132.    {
  133.        MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, FALSE);
  134.        return;
  135.    }
  136.  
  137.    hini.pszHelpLibraryName = (PSZ)szLibName;
  138.  
  139.                    /* creating help instance */
  140.    hwndHelpInstance = WinCreateHelpInstance(hab, &hini);
  141.  
  142.    if(!hwndHelpInstance)
  143.    {
  144.        MessageBox(hwndMain, IDMSG_HELPNOTAVAILABLE, MB_OK | MB_ERROR, TRUE);
  145.        return;
  146.    }
  147.  
  148.    if(hini.ulReturnCode)
  149.    {
  150.        MessageBox(hwndMain, IDMSG_HELPCREATEERROR, MB_OK | MB_ERROR, TRUE);
  151.        return;
  152.    }
  153.  
  154.                 /* associate help instance with main frame */
  155.    if(!WinAssociateHelpInstance(hwndHelpInstance, hwndMain))
  156.    {
  157.        MessageBox(hwndMain, IDMSG_HELPASSOCIATEERROR, MB_OK | MB_ERROR, TRUE);
  158.        return;
  159.    }
  160.  
  161.    /* help manager is successfully initialized so set flag to TRUE */
  162.    fHelpEnabled = TRUE;
  163. }   /*  End of InitHelp  */
  164.  
  165. /**************************************************************************
  166.  *
  167.  *  Name       :  HelpUsingHelp(hwnd)
  168.  *
  169.  *  Description: Processes the Using help choice from the Help pulldown
  170.  *
  171.  *  Concepts   : Processes the WM_COMMAND message posted by the
  172.  *               Using Help item of the Help menu
  173.  *               Called from MainCommand when the Using Help
  174.  *               menu item is selected
  175.  *               Sends an HM_DISPLAY_HELP message to the help
  176.  *               instance so that the default Using Help is
  177.  *               displayed.
  178.  *
  179.  *  API's      :   WinSendMsg
  180.  *
  181.  *  Parameters :  hwndMain = main window handle
  182.  *
  183.  *  Return     :  [none]
  184.  *
  185.  *************************************************************************/
  186. VOID  HelpUsingHelp(HWND hwndMain)
  187. {
  188.     /* this just displays the system using help panel */
  189.     if(fHelpEnabled)
  190.        if (NULL != WinSendMsg(hwndHelpInstance, HM_DISPLAY_HELP,
  191.                           (MPARAM)NULL, (MPARAM)NULL))
  192.         {
  193.             MessageBox(hwndMain, IDMSG_HELPDISPLAYERROR, MB_OK | MB_ERROR,
  194.                        FALSE);
  195.         }
  196. }   /* End of HelpUsingHelp   */
  197.  
  198.  
  199. /**************************************************************************
  200.  *
  201.  *  Name       :  HelpGeneral(hwnd)
  202.  *
  203.  *  Description: Processes the General help choice from the Help pulldown
  204.  *
  205.  *  Concepts   : Processes the WM_COMMAND message posted by the
  206.  *               General Help item of the Help menu
  207.  *               Called from MainCommand when the General Help
  208.  *               menu item is selected
  209.  *               Sends an HM_EXT_HELP message to the help
  210.  *               instance so that the default Extended Help is
  211.  *               displayed.
  212.  *
  213.  *  API's      :   WinSendMsg
  214.  *
  215.  *  Parameters :  hwndMain = main window handle
  216.  *
  217.  *  Return     :  [none]
  218.  *
  219.  *************************************************************************/
  220. VOID  HelpGeneral(HWND hwndMain)
  221. {
  222.     /* this just displays the system general help panel */
  223.     if(fHelpEnabled)
  224.         if(NULL != WinSendMsg(hwndHelpInstance, HM_EXT_HELP,
  225.                       (MPARAM)NULL, (MPARAM)NULL))
  226.             MessageBox(hwndMain,
  227.                        IDMSG_HELPDISPLAYERROR,
  228.                        MB_OK | MB_ERROR,
  229.                        FALSE);
  230. }   /* End of HelpGeneral   */
  231.  
  232.  
  233. /**************************************************************************
  234.  *
  235.  *  Name       :  HelpIndex(hwnd)
  236.  *
  237.  *  Description: Processes the Help index choice from the Help pulldown
  238.  *
  239.  *  Concepts   : Processes the WM_COMMAND message posted by the
  240.  *               Help index item of the Help menu
  241.  *               Called from MainCommand when the Help index
  242.  *               menu item is selected
  243.  *               Sends an HM_INDEX_HELP message to the help
  244.  *               instance so that the Help index is displayed.
  245.  *
  246.  *  API's      :  WinSendMsg
  247.  *
  248.  *  Parameters :  hwndMain = main window handle
  249.  *
  250.  *  Return     :  [none]
  251.  *
  252.  *************************************************************************/
  253. VOID  HelpIndex(HWND hwndMain)
  254. {
  255.     /* this just displays the system help index panel */
  256.     if(fHelpEnabled)
  257.         if(NULL != WinSendMsg(hwndHelpInstance, HM_HELP_INDEX,
  258.                       (MPARAM)NULL, (MPARAM)NULL))
  259.             MessageBox(hwndMain,
  260.                        IDMSG_HELPDISPLAYERROR,
  261.                        MB_OK | MB_ERROR,
  262.                        FALSE);
  263. }   /* End of HelpIndex   */
  264.  
  265.  
  266. /**************************************************************************
  267.  *
  268.  *  Name       :  HelpProductInfo(hwndMain)
  269.  *
  270.  *  Description: Processes the Product information choice from the Help
  271.  *               pulldown
  272.  *
  273.  *  Concepts   : Processes the WM_COMMAND message posted by the
  274.  *               Product information item of the Help menu
  275.  *               Called from MainCommand when the Product information
  276.  *               menu item is selected
  277.  *               Calls WinDlgBox to display the Product information
  278.  *               dialog.
  279.  *
  280.  *  API's      :  WinSendMsg
  281.  *
  282.  *  Parameters :  hwndMain = main window handle
  283.  *
  284.  *  Return     :  [none]
  285.  *
  286.  *************************************************************************/
  287. VOID  HelpProductInfo(HWND hwndMain)
  288. {
  289.     /* display the Product Information dialog. */
  290.     if(DID_ERROR == WinDlgBox(HWND_DESKTOP,
  291.                               hwndMain,
  292.                               (PFNWP)ProductInfoDlgProc,
  293.                               0,
  294.                               IDD_PRODUCTINFO,
  295.                               (PVOID)NULL))
  296.  
  297.         MessageBox(HWND_DESKTOP,
  298.                    IDMSG_CANTSTARTDIALOG ,
  299.                    MB_OK | MB_ERROR,
  300.                    TRUE);
  301. }   /*  End of HelpProductInfo   */
  302.  
  303. /**************************************************************************
  304.  *
  305.  *  Name       :  DestroyHelpInstance()
  306.  *
  307.  *  Description:  Deletes the application's help instance
  308.  *
  309.  *  Concepts   : Calls WinDestroyHelp Instance to delete the instance
  310.  *
  311.  *  API's      :  WinDestroyHelpInstance
  312.  *
  313.  *  Parameters :  [none]
  314.  *
  315.  *  Return     :  [none]
  316.  *
  317.  *************************************************************************/
  318. VOID DestroyHelpInstance(VOID)
  319. {
  320.     if(hwndHelpInstance != 0L)
  321.     {
  322.         WinDestroyHelpInstance(hwndHelpInstance);
  323.     }
  324. }   /* End of DestroyHelpInstance    */
  325.  
  326.  
  327. /**************************************************************************
  328.  *
  329.  *  Name       :  ProductInfoDlgProc(hwnd, msg, mp1, mp2)
  330.  *
  331.  *  Description:  Processes all messages sent to the Product
  332.  *                information dialog
  333.  *
  334.  *  Concepts   :  Called for each message sent to the Product information
  335.  *                dialog box.
  336.  *
  337.  *                the Product information dialog has only a button control, so this
  338.  *                routine processes only WM_COMMAND messages.  Any
  339.  *                WM_COMMAND posted must have come from the OK
  340.  *                button, so we dismiss the dialog upon receiving it.
  341.  *
  342.  *  API's      :  WinDefDlgProc
  343.  *
  344.  *  Parameters :  [none]
  345.  *
  346.  *  Return     :  dependent on message sent
  347.  *
  348.  *************************************************************************/
  349. MRESULT EXPENTRY ProductInfoDlgProc(HWND hwnd,
  350.                                     USHORT msg,
  351.                                     MPARAM mp1,
  352.                                     MPARAM mp2)
  353. {
  354.     switch (msg)
  355.     {
  356.     case WM_INITDLG:
  357.        SetSysMenu(hwnd);       /* system menu for this dialog  */
  358.           return (MRESULT)NULL;
  359.  
  360.     default:
  361.        return WinDefDlgProc(hwnd, msg, mp1, mp2);
  362.     }
  363.     return (MRESULT)NULL;
  364. }   /*  End of ProductInfoDlgProc  */
  365.  
  366. /**************************************************************************
  367.  *
  368.  *  Name       :  SetSysMenu(hDlg)
  369.  *
  370.  *  Description:  Enables only the Move and Close items in the
  371.  *                system menu pulldown for any dialog
  372.  *
  373.  *  Concepts   :
  374.  *
  375.  *  API's      :  WinWindowFromID
  376.  *                WinSendMsg
  377.  *
  378.  *  Parameters :  hDlg = dialog handle
  379.  *
  380.  *  Return     :  [none]
  381.  *
  382.  *************************************************************************/
  383. VOID SetSysMenu( HWND hDlg )
  384. {
  385.     HWND     hSysMenu;
  386.     MENUITEM Mi;
  387.     SHORT    Pos;
  388.     ULONG    Id;
  389.     SHORT    cItems;
  390.  
  391.     /*
  392.      *  We only want Move and Close in the system menu.
  393.      */
  394.     hSysMenu = WinWindowFromID(hDlg, FID_SYSMENU);
  395.     WinSendMsg( hSysMenu, MM_QUERYITEM
  396.               , MPFROM2SHORT(SC_SYSMENU, FALSE), MPFROMP((PCH) & Mi));
  397.     Pos = 0;
  398.     cItems = (SHORT)WinSendMsg( Mi.hwndSubMenu, MM_QUERYITEMCOUNT,
  399.                                 (MPARAM)NULL, (MPARAM)NULL);
  400.     while (cItems--)
  401.     {
  402.         Id = (ULONG) WinSendMsg( Mi.hwndSubMenu, MM_ITEMIDFROMPOSITION
  403.                           , MPFROM2SHORT(Pos, TRUE), (MPARAM)NULL);
  404.         switch (SHORT1FROMMP(Id))
  405.         {
  406.         case SC_MOVE:
  407.         case SC_CLOSE:
  408.             Pos++;  /* Don't delete that one. */
  409.             break;
  410.         default:
  411.             WinSendMsg( Mi.hwndSubMenu, MM_DELETEITEM
  412.                       , MPFROM2SHORT(Id, TRUE), (MPARAM)NULL);
  413.         }
  414.     }
  415. } /*  End of SetSysMenu  */
  416. /***************************  End of draghelp.c  *************************/
  417.