home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / WHEEL1.ZIP / TELLUSER.C < prev    next >
Text File  |  1990-02-12  |  3KB  |  113 lines

  1. // Includes
  2. // --------
  3.    #define  INCL_WIN
  4.    #define  INCL_DOS
  5.    #include <os2.h>
  6.  
  7.    #include "stdio.h"                  // Changed from <..> for Eikon
  8.    #include "stdarg.h"                 // Changed from <..> for Eikon
  9.    #include "string.h"                 // Changed from <..> for Eikon
  10.  
  11.    #include "TellUser.H"
  12.  
  13.  
  14. // Constants
  15. // ---------
  16.    #define MAX_STRING 128              // Maximum string size
  17.  
  18.  
  19. // Function Declarations (see also TellUser.H)
  20. // -------------------------------------------
  21.    VOID EXPENTRY TellUserInitialize (VOID);
  22.  
  23.  
  24. // Function: TellUserInitialize - Initialize TellUser processing
  25. // -------------------------------------------------------------
  26.    VOID EXPENTRY TellUserInitialize (VOID)
  27.  
  28.    // Define function data
  29.  
  30.      {static DOSFSRSEM dosfsrs;         // Semaphore to block registration
  31.       static BOOL fRegistered = FALSE;  // TRUE if already registered
  32.  
  33.    // Block the actions that follow such that only one process at a
  34.    // time executes them.
  35.  
  36.       DosFSRamSemRequest (&dosfsrs, SEM_INDEFINITE_WAIT);
  37.  
  38.    // Perform dummy initialization
  39.  
  40.       if (! fRegistered)
  41.         {
  42.          fRegistered = TRUE;
  43.         }
  44.  
  45.    // Release the block and return
  46.  
  47.       DosFSRamSemClear (&dosfsrs);
  48.      }
  49.  
  50.  
  51. // Function: TellUser - Issue message to User
  52. // ------------------------------------------
  53.    USHORT FAR TellUser (idMsg, pszDLLName, flStyle, ...)
  54.  
  55.       USHORT idMsg;                    // Message identifier
  56.       PCHAR pszDLLName;                // Module name where resource exists
  57.       USHORT flStyle;                  // Message style
  58.  
  59.    // Define function data
  60.  
  61.      {CHAR szFormat[MAX_STRING];       // Message format
  62.       CHAR szBuffer[MAX_STRING];       // Message buffer
  63.       CHAR szCaption[MAX_STRING];      // Message caption
  64.       USHORT usResponse;               // Message response
  65.       HMODULE hmod = NULL;             // Requesting module handle
  66.       va_list pArgs;                   // String substitution arguments
  67.       PCHAR pszDot;                    // Temporary pointer
  68.       int i;                           // Temporary integer
  69.  
  70.    // Extract the message caption from the DLL name.
  71.  
  72.       strcpy (szCaption, pszDLLName);
  73.       if ((pszDot = strrchr (szCaption, '.')) != NULL)
  74.         *pszDot = 0;
  75.  
  76.    // Get the handle of the module holding the message string
  77.  
  78.       i = strlen (pszDLLName);
  79.       if ((i > 4) && (strcmpi (pszDLLName+i-4, ".DLL") == 0))
  80.         {if (DosLoadModule (szBuffer, sizeof (szBuffer), szCaption, &hmod))
  81.             hmod = NULL;
  82.         }
  83.  
  84.    // Load the message string
  85.  
  86.       WinLoadString (NULL, hmod, idMsg, sizeof (szFormat), szFormat);
  87.  
  88.    // Free the handle of the module holding the message string
  89.  
  90.       if (hmod != NULL)
  91.          DosFreeModule (hmod);
  92.  
  93.    // Build the message text.
  94.  
  95.       va_start (pArgs, flStyle);
  96.       vsprintf (szBuffer, szFormat, pArgs);
  97.       va_end (pArgs);
  98.  
  99.    // Display the message and capture response
  100.  
  101.       usResponse = WinMessageBox (HWND_DESKTOP, HWND_DESKTOP, szBuffer,
  102.          szCaption, idMsg, flStyle);
  103.  
  104.    // Terminate if response is "abort"
  105.  
  106.       if (usResponse == MBID_ABORT)
  107.          DosExit (EXIT_PROCESS, 0);
  108.  
  109.    // Return response
  110.  
  111.       return usResponse;
  112.      }
  113.