home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / graphic / showbmp / utility.c < prev    next >
Text File  |  1990-06-19  |  8KB  |  189 lines

  1. #define PROGRAM       "UTILITY"        // Program Name
  2. #define LEVEL         "Level 00"       // Program Level
  3. #define COPYRIGHT     "Copyright (c) 1990 George S. Brickner"
  4.  
  5. #pragma title (PROGRAM " " LEVEL " - Misc Utilities")
  6. #pragma linesize(120)
  7. #pragma pagesize(55)
  8.  
  9. /*****************************************************************************
  10. **                                                                          **
  11. **          UTILITY - Misc Presentation Manager Utility Routines.           **
  12. **                      Level 00, June 19th, 1990                           **
  13. **                                                                          **
  14. *****************************************************************************/
  15. #define  INCL_DOS                      // Include OS/2 Doscalls
  16. #define  INCL_WIN                      // Include OS/2 PM Win Calls
  17. #define  INCL_ERRORS                   // Include All OS/2 Errors
  18. #include <os2.h>                       // Standard OS/2 Definitions
  19.  
  20. #include <mt\string.h>                 // C/2 Standard String Defs
  21. #include <mt\stdlib.h>                 // C/2 Standard Library Defs
  22. #include <mt\stdio.h>                  // C/2 Standard I/O Defs
  23.  
  24. #include <SHOWBMP.h>                   // SHOWBMP Header File
  25. #include <UTILITY.h>                   // UTILITY Header File
  26.  
  27. /********************************************************************
  28. **                     Define Static & External Data               **
  29. ********************************************************************/
  30. static CHAR const eyepopper[] = PROGRAM "-" LEVEL "-" __TIMESTAMP__ "-" COPYRIGHT;
  31.  
  32. extern CHAR   szClientClass[];         // Client class string
  33. extern HWND   hwndFrame;               // Frame window handle
  34.  
  35. #pragma subtitle ("Display Message Box")
  36. #pragma page()
  37. /********************************************************************
  38. **                       Display Message Box                       **
  39. ********************************************************************/
  40. USHORT DisplayMsgBox (BOOL Beep, PCHAR Msg, PCHAR Title, USHORT Style)
  41.   {
  42.     if (Beep)                          // Sound Alarm
  43.       {
  44.         WinAlarm (HWND_DESKTOP, WA_ERROR); // Beep User
  45.       }
  46.  
  47.     return WinMessageBox (             // Display Error Msg
  48.                HWND_DESKTOP,           // Parent Window
  49.                HWND_DESKTOP,           // Parent Window
  50.                Msg,                    // Message Text
  51.                Title,                  // Caption
  52.                0,                      // Help Hook
  53.                Style);                 // Msg Box Style
  54.   }
  55.  
  56. #pragma subtitle ("Show PM Error")
  57. #pragma page()
  58. /********************************************************************
  59. **                    Show PM Error Via Message Box                **
  60. ********************************************************************/
  61. VOID ShowPMError (HAB hab, USHORT id)
  62.   {
  63.   ERRORID  err;                        // Error ID
  64.   PERRINFO pErr;                       // PM Error Info Handle Ptr
  65.   PUSHORT  pRetCode;                   // OS/2 Return Code ptr
  66.   USHORT   rc = NO_ERROR;              // Return Code
  67.   USHORT   size;                       // String Size
  68.   CHAR     szMsg[256];                 // Message Work Area
  69.   CHAR     szFormat[256];              // Format Area
  70.   CHAR     szMessage[256];             // Finished Message Area
  71.   CHAR     szCaption[256];             // Caption Area
  72.  
  73.     if (pErr = WinGetErrorInfo (hab))  // Then use error info
  74.       {
  75.         err = pErr->idError;           // Save error id code
  76.  
  77.         if (pErr->offBinaryData)       // Return code provided
  78.           {
  79.             SELECTOROF (pRetCode) = SELECTOROF (pErr);
  80.             OFFSETOF (pRetCode) = pErr->offBinaryData;
  81.             rc = *pRetCode;            // Save return code
  82.           }
  83.       }
  84.     else                               // Just use Last Error
  85.       {
  86.         err = WinGetLastError (hab);
  87.       }
  88.  
  89.     WinLoadString (hab, (HMODULE) NULL, IDS_FORMAT01, sizeof szFormat, szFormat);
  90.     WinLoadString (hab, (HMODULE) NULL, id, sizeof szMsg, szMsg);
  91.  
  92.     sprintf (szMessage, szFormat, szMsg, '\r',
  93.         ERRORIDSEV (err), ERRORIDERROR (err), '\r', rc);
  94.  
  95.     strcpy (szCaption, szClientClass);
  96.     size = strlen (szCaption);
  97.     WinLoadString (hab, (HMODULE) NULL, IDS_ERROR, sizeof szCaption - size, &szCaption[size]);
  98.     DisplayMsgBox (TRUE, szMessage, szCaption, MB_OK | MB_CUACRITICAL);
  99.  
  100.     if (pErr)                          // Perform cleanup
  101.       {
  102.         WinFreeErrorInfo (pErr);       // Cleanup
  103.       }
  104.   }
  105.  
  106. #pragma subtitle ("Show DOS Error")
  107. #pragma page()
  108. /********************************************************************
  109. **                    Show DOS Error Via Message Box               **
  110. ********************************************************************/
  111. VOID ShowDOSError (HAB hab, USHORT rc, USHORT id)
  112.   {
  113.   USHORT  size;                        // String Size
  114.   CHAR    szMsg[256];                  // Message Work Area
  115.   CHAR    szFormat[256];               // Format Area
  116.   CHAR    szMessage[256];              // Message Area
  117.   CHAR    szCaption[256];              // Caption Area
  118.  
  119.     WinLoadString (hab, (HMODULE) NULL, IDS_FORMAT02, sizeof szFormat, szFormat);
  120.     WinLoadString (hab, (HMODULE) NULL, id, sizeof szMsg, szMsg);
  121.  
  122.     sprintf (szMessage, szFormat, szMsg, rc, rc);
  123.  
  124.     strcpy (szCaption, szClientClass);
  125.     size = strlen (szCaption);
  126.     DisplayMsgBox (TRUE, szMessage, szCaption, MB_OK | MB_CUACRITICAL);
  127.   }
  128.  
  129. #pragma subtitle ("Show Debug Data")
  130. #pragma page()
  131. /********************************************************************
  132. **                   Show Debug Data Via Message Box               **
  133. ********************************************************************/
  134. VOID ShowDebug (HAB hab, SHORT rc, PCHAR msg)
  135.   {
  136.   USHORT  size;                        // String Size
  137.   CHAR    szFormat[256];               // Format Area
  138.   CHAR    szMessage[256];              // Message Area
  139.   CHAR    szCaption[256];              // Caption Area
  140.  
  141.     WinLoadString (hab, (HMODULE) NULL, IDS_FORMAT03, sizeof szFormat, szFormat);
  142.  
  143.     sprintf (szMessage, szFormat, msg, rc, rc);
  144.  
  145.     strcpy (szCaption, szClientClass);
  146.     size = strlen (szCaption);
  147.     WinLoadString (hab, (HMODULE) NULL, IDS_DEBUG, sizeof szCaption - size, &szCaption[size]);
  148.     DisplayMsgBox (FALSE, szMessage, szCaption, MB_OK);
  149.   }
  150.  
  151. #pragma subtitle ("Display Busy Pointer")
  152. #pragma page()
  153. /********************************************************************
  154. **                      Display Busy Pointer                       **
  155. ********************************************************************/
  156. VOID DisplayBusyPtr (BOOL Busy)
  157.   {
  158.   BOOL Mouse;                          // Display Pointer If No Mouse
  159.  
  160.     if (Busy)                          // Display Busy Pointer
  161.       {
  162.         WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (HWND_DESKTOP, SPTR_WAIT, FALSE));
  163.         Mouse = TRUE;
  164.       }
  165.     else                               // Display Normal Pointer
  166.       {
  167.         WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (HWND_DESKTOP, SPTR_ARROW, FALSE));
  168.         Mouse = FALSE;
  169.       }
  170.  
  171.     if (WinQuerySysValue (HWND_DESKTOP, SV_MOUSEPRESENT) == 0) // No Mouse
  172.       {
  173.         WinShowPointer (HWND_DESKTOP, Mouse);
  174.       }
  175.   }
  176.  
  177. #pragma subtitle ("Enable/Disable Menu Items")
  178. #pragma page()
  179. /********************************************************************
  180. **                Enable and Disable Menu Items                    **
  181. ********************************************************************/
  182. VOID EnableMenuItem (SHORT idItem, BOOL fEnable)
  183.   {
  184.     WinSendMsg (WinWindowFromID (hwndFrame, FID_MENU),
  185.                 MM_SETITEMATTR,
  186.                 MPFROM2SHORT (idItem, TRUE),
  187.                 MPFROM2SHORT (MIA_DISABLED, fEnable ? ~MIA_DISABLED : MIA_DISABLED)) ;
  188.   }
  189.