home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cscout.zip / SAMPLES / MISC.C < prev    next >
Text File  |  1995-06-12  |  13KB  |  309 lines

  1. /************************************************************************/
  2. /***                                                                  ***/
  3. /*** AUTHOR            : RH                                           ***/
  4. /***                                                                  ***/
  5. /*** SHORT DESCRIPTION : miscellaneous helper functions for all       ***/
  6. /***                     mtestpm modules which need them              ***/
  7. /***                                                                  ***/
  8. /*** PART OF           : mtestpm                                      ***/
  9. /***                                                                  ***/
  10. /*** COPYRIGHT         : (C) 1995 a priori Computer Solutions GmbH    ***/
  11. /***                                                                  ***/
  12. /************************************************************************/
  13.  
  14. #ifdef __IBMC__
  15. #pragma strings(readonly)
  16. #endif
  17.  
  18. /*----------------------------------------------------------------------*/
  19. /* includes                                                             */
  20. /*----------------------------------------------------------------------*/
  21.  
  22. #define INCL_BASE
  23. #define INCL_PM
  24. #include <os2.h>
  25.  
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <stdlib.h>
  29.  
  30. /*--------------------------------------*/
  31. /* Define trace levels                  */
  32. /*--------------------------------------*/
  33. #define   DATT_BASE_LEVEL   2000
  34. #define   DATT_TM_LEVEL     2001
  35. #define   TM_I              DATT_BASE_LEVEL + 1   /* Info */
  36. #define   TM_E              DATT_BASE_LEVEL + 2   /* error */
  37. #define   TM_H              DATT_BASE_LEVEL + 3   /* hex dump */
  38.  
  39. /*--------------------------------------*/
  40. /* include the C-Scout definitions here */
  41. /*--------------------------------------*/
  42. #include "datt.h"
  43.  
  44. // mtestpm common definitions
  45. #include "mtestpm.h"
  46.  
  47. // mtestpm resource id definitions
  48. #include "resid.h"
  49.  
  50. /*----------------------------------------------------------------------*/
  51. /* defines                                                              */
  52. /*----------------------------------------------------------------------*/
  53.  
  54. #define ABOUT_TEXT "~About"
  55.  
  56. /*----------------------------------------------------------------------*/
  57. /* external static variables                                            */
  58. /*----------------------------------------------------------------------*/
  59. /* anchor block handle of mtestpm.c  */
  60. extern HAB habThis ;
  61.  
  62. /* help instance data                 */
  63. static HWND hwndHelpInstance;
  64. static BOOL fHelpEnabled;
  65.  
  66. /************************************************************************/
  67. /* FUNCTION-NAME       : MiscDisplayMsg                                 */
  68. /*                                                                      */
  69. /* DESCRIPTION         : centers the dialog into given HWND's client    */
  70. /*                                                                      */
  71. /* PARAMETERS          : hwndOwner - window handle of the owner of the  */
  72. /*                                   message box                        */
  73. /*                       idMsg     - id of message to be retrieved from */
  74. /*                                   resource file                      */
  75. /*                       fsStyle   - message box style                  */
  76. /*                       fBeep     - flag to sound alarm                */
  77. /*                                                                      */
  78. /* RETURN-VALUE        : none                                           */
  79. /*                                                                      */
  80. /************************************************************************/
  81. VOID MiscDisplayMsg ( HWND    hwndOwner,
  82.                       SHORT   idMsg,
  83.                       SHORT   fsStyle,
  84.                       BOOL    fBeep )
  85.   {
  86.   CHAR szText[MESSAGELEN];
  87.  
  88.   FncEntry();
  89.  
  90.   TX( !WinLoadMessage( habThis,
  91.                        (HMODULE)NULL,
  92.                        idMsg,
  93.                        MESSAGELEN,
  94.                        (PSZ)szText ) );
  95.  
  96.   if (fBeep) WinAlarm(HWND_DESKTOP, WA_ERROR);
  97.  
  98.   TX( WinMessageBox( HWND_DESKTOP,
  99.                      hwndOwner,
  100.                      szText,
  101.                      (PSZ)NULL,
  102.                      IDD_MSGBOX,
  103.                      fsStyle ) == MBID_ERROR );
  104.  
  105.   FncExitVoid();
  106.   }  /* MiscDisplayMsg        */
  107.  
  108. /************************************************************************/
  109. /* FUNCTION-NAME       : MiscCenterDialog                               */
  110. /*                                                                      */
  111. /* DESCRIPTION         : centers the dialog into given HWND's client    */
  112. /*                                                                      */
  113. /* PARAMETERS          : parent hwnd, dialog hwnd                       */
  114. /*                                                                      */
  115. /* RETURN-VALUE        : none                                           */
  116. /*                                                                      */
  117. /************************************************************************/
  118. VOID MiscCenterDialog( HWND   hwndParent,
  119.                        HWND   hwndDialog)
  120.   {
  121.   SHORT  cx, cy;          /* New x and y location for dialog box. */
  122.   SWP    swpParent;
  123.   SWP    swpDialog;
  124.  
  125.   FncEntry();
  126.  
  127.   /*---------------------------------------------------------------*/
  128.   /* Determine the current size (and position) of given parent     */
  129.   /*---------------------------------------------------------------*/
  130.   TX( !WinQueryWindowPos(hwndParent, (PSWP)&swpParent) );
  131.  
  132.   /*---------------------------------------------------------------*/
  133.   /* Determine the current size (and position) of the dialog box.  */
  134.   /*---------------------------------------------------------------*/
  135.   TX( !WinQueryWindowPos(hwndDialog, (PSWP)&swpDialog) );
  136.  
  137.   /*---------------------------------------------------------------*/
  138.   /* Calculate the correct new x and y location of the dialog box. */
  139.   /*---------------------------------------------------------------*/
  140.   cx = (swpParent.cx - swpDialog.cx) / 2;
  141.   cy = (swpParent.cy - swpDialog.cy) / 2;
  142.  
  143.   /*--------------------------------------------------------------*/
  144.   /* Set the position of the dialog box to the new x and y values.*/
  145.   /*--------------------------------------------------------------*/
  146.   TX( !WinSetWindowPos( hwndDialog,
  147.                         HWND_TOP,
  148.                         cx,
  149.                         cy,
  150.                         0,
  151.                         0,
  152.                         SWP_MOVE ) );
  153.  
  154.   FncExitVoid();
  155.  
  156.   } /* MiscCenterDialog */
  157.  
  158. /************************************************************************/
  159. /* FUNCTION-NAME       : MiscInitHelp                                   */
  160. /*                                                                      */
  161. /* DESCRIPTION         : Initializes the IPF help facility              */
  162. /*                                                                      */
  163. /* PARAMETERS          : hwnd to associate with                         */
  164. /*                                                                      */
  165. /* RETURN-VALUE        : none                                           */
  166. /*                                                                      */
  167. /************************************************************************/
  168. VOID MiscInitHelp(HWND hwnd)
  169.   {
  170.   HELPINIT helpInit;
  171.  
  172.   FncEntry();
  173.  
  174.   /*--------------------------------------------------------------*/
  175.   /* if we return because of an error, Help will be disabled      */
  176.   /*--------------------------------------------------------------*/
  177.   fHelpEnabled = FALSE;
  178.  
  179.   /*--------------------------------------------------------------*/
  180.   /* inititalize help init structure                              */
  181.   /*--------------------------------------------------------------*/
  182.  
  183.   helpInit.cb = sizeof(HELPINIT);
  184.   helpInit.ulReturnCode = 0L;
  185.   helpInit.pszTutorialName = (PSZ)NULL;
  186.   helpInit.phtHelpTable = (PHELPTABLE)MAKELONG(HELPTABLE_mtestpm,
  187.                                                0xFFFF);
  188.   helpInit.hmodHelpTableModule = (HMODULE)0;
  189.   helpInit.hmodAccelActionBarModule = (HMODULE)0;
  190.   helpInit.idAccelTable = 0;
  191.   helpInit.idActionBar = 0;
  192.   helpInit.pszHelpWindowTitle = (PSZ) "mtestpm Help";
  193.   helpInit.fShowPanelId = CMIC_HIDE_PANEL_ID;
  194.   helpInit.pszHelpLibraryName = (PSZ)"mtestpm.hlp";
  195.  
  196.   /*--------------------------------------------------------------*/
  197.   /* creating help instance                                       */
  198.   /*--------------------------------------------------------------*/
  199.   hwndHelpInstance = WinCreateHelpInstance(habThis, &helpInit);
  200.  
  201.   if (!hwndHelpInstance || helpInit.ulReturnCode)
  202.      {
  203.      MiscDisplayMsg( hwnd,
  204.                      IDMSG_HELPLOADERROR,
  205.                      MB_OK | MB_ERROR,
  206.                      TRUE );
  207.      FncExitVoid();
  208.      }
  209.  
  210.   /*--------------------------------------------------------------*/
  211.   /* associate help instance with main frame                      */
  212.   /*--------------------------------------------------------------*/
  213.   if ( !WinAssociateHelpInstance(hwndHelpInstance, hwnd))
  214.      {
  215.      MiscDisplayMsg( hwnd,
  216.                      IDMSG_HELPLOADERROR,
  217.                      MB_OK | MB_ERROR,
  218.                      TRUE );
  219.      FncExitVoid();
  220.      }
  221.  
  222.   /*--------------------------------------------------------------*/
  223.   /* help manager is successfully initialized so set flag to TRUE */
  224.   /*--------------------------------------------------------------*/
  225.   fHelpEnabled = TRUE;
  226.  
  227.   FncExitVoid();
  228.  
  229.   } /* MiscInitHelp  */
  230.  
  231. /************************************************************************/
  232. /* FUNCTION-NAME       : MiscDisplayHelp                                */
  233. /*                                                                      */
  234. /* DESCRIPTION         : displays the desired help panel                */
  235. /*                                                                      */
  236. /* PARAMETERS          : help msg HM_EXT_HELP                           */
  237. /*                                HM_KEYS_HELP                          */
  238. /*                                HM_HELP_INDEX                         */
  239. /*                                HM_EXT_HELP                           */
  240. /*                                HM_DISPLAY_HELP + panelid             */
  241. /*                                                                      */
  242. /* RETURN-VALUE        : none                                           */
  243. /*                                                                      */
  244. /************************************************************************/
  245. VOID  MiscDisplayHelp(ULONG msg, USHORT usPanelId)
  246.   {
  247.   FncEntry();
  248.  
  249.   if (fHelpEnabled)
  250.      {
  251.      switch (msg)
  252.         {
  253.         case HM_EXT_HELP :
  254.         case HM_KEYS_HELP :
  255.         case HM_HELP_INDEX:
  256.              if ( (BOOL)WinSendMsg(hwndHelpInstance, msg, NULL, NULL) )
  257.                 MiscDisplayMsg( HWND_DESKTOP,
  258.                                 IDMSG_HELPDISPLAYERROR,
  259.                                 MB_OK | MB_ERROR,
  260.                                 FALSE );
  261.              break;
  262.  
  263.         case HM_DISPLAY_HELP:
  264.              if ( (BOOL)WinSendMsg( hwndHelpInstance,
  265.                                     HM_DISPLAY_HELP,
  266.                                     MPFROM2SHORT(usPanelId, NULL),
  267.                                     MPFROMSHORT(HM_RESOURCEID) ) )
  268.                 MiscDisplayMsg( HWND_DESKTOP,
  269.                                 IDMSG_HELPDISPLAYERROR,
  270.                                 MB_OK | MB_ERROR,
  271.                                 FALSE );
  272.              break;
  273.  
  274.         default:
  275.              break;
  276.  
  277.         }
  278.      }
  279.  
  280.   FncExitVoid();
  281.  
  282.   } /* MiscDisplayHelp      */
  283.  
  284.  
  285. /************************************************************************/
  286. /* FUNCTION-NAME       : MiscDestroyHelp                                */
  287. /*                                                                      */
  288. /* DESCRIPTION         : destroys the help instance                     */
  289. /*                                                                      */
  290. /* PARAMETERS          : hwnd to associate with                         */
  291. /*                                                                      */
  292. /* RETURN-VALUE        : none                                           */
  293. /*                                                                      */
  294. /************************************************************************/
  295. VOID MiscDestroyHelp()
  296.   {
  297.   FncEntry();
  298.  
  299.   if (hwndHelpInstance)
  300.      WinDestroyHelpInstance(hwndHelpInstance);
  301.  
  302.   FncExitVoid();
  303.  
  304.   } /* MiscDestroyHelp    */
  305.  
  306. /************************************************************************/
  307. /*** EOF misc.c                                                       ***/
  308. /************************************************************************/
  309.