home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / PMMSG10.ZIP / PMMESSAG.C next >
Text File  |  1991-02-12  |  3KB  |  114 lines

  1. /* ----------------------------------------------------------------------
  2.    PMMESSAGE.C -- This will display a message box with the info passed
  3.    ---------------------------------------------------------------------- */
  4.  
  5. #define INCL_WIN
  6. #define INCL_DOSERRORS
  7. #define INCL_SHLERRORS
  8. #define INCL_DOSMISC
  9. #define _MT
  10. #include <os2.h>
  11. #include <malloc.h>
  12. #include <process.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include "pmmessag.h"
  16.  
  17. /* Global variables */
  18.  
  19. HAB           hab;         /* Handle to an anchor block */
  20.  
  21. /**
  22. *** ═════════════════════════════════════════════════════════════════════════
  23. **/
  24.  
  25. int main(int argc, char *argv[])
  26.    {
  27.    HMQ     hmq;         /* Handle to a message queue */
  28.    QMSG    qmsg;        /* A queued message */
  29.    CHAR    szText[SZS_TEXT]; /* Message text */
  30.  
  31.    /* Check for a filename from the command line */
  32.  
  33.    hab = WinInitialize(0);
  34.    hmq = WinCreateMsgQueue(hab,0);
  35.  
  36.    WinRegisterClass(hab, CLIENTCLASS, MessageWndProc, 0L, 0);
  37.  
  38.    if (ParseCommandLine(argc, argv, szText) != NO_ERROR)
  39.       return 0;
  40.  
  41.    /* Create a window so we can pop the message box */
  42.  
  43.    WinCreateWindow(HWND_DESKTOP,      /* Parent            */
  44.                    CLIENTCLASS,       /* Registered Class  */
  45.                    NULL,              /* Window text       */
  46.                    0L,                /* Styles            */
  47.                    0, 0,              /* Position          */
  48.                    0, 0,              /* Sizes             */
  49.                    HWND_DESKTOP,      /* Owner             */
  50.                    HWND_BOTTOM,       /* Put it on bottom  */
  51.                    IDW_MAIN,          /* Control ID        */
  52.                    szText,            /* Class specific    */
  53.                    NULL);             /* Presentation Parm */
  54.  
  55.    while(WinGetMsg(hab, &qmsg, NULL, 0, 0))
  56.       WinDispatchMsg(hab,&qmsg);
  57.  
  58.    WinDestroyMsgQueue(hmq);
  59.    WinTerminate(hab);
  60.    return 0;
  61.    } /* Main */
  62.  
  63. /**
  64. *** ═════════════════════════════════════════════════════════════════════════
  65. ***     Primary dialog procedure
  66. *** ═════════════════════════════════════════════════════════════════════════
  67. **/
  68.  
  69. MRESULT EXPENTRY MessageWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  70.    {
  71.    PSZ pszText;        /* Pointer to the text */
  72.  
  73.    switch(msg)
  74.       {
  75.       case WM_CREATE:
  76.  
  77.          pszText = PVOIDFROMMP(mp1);
  78.  
  79.          /* If alarms are turned on in the control panel, beep the bell */
  80.  
  81.          if (WinQuerySysValue(HWND_DESKTOP, SV_ALARM))
  82.             WinAlarm(HWND_DESKTOP,WA_NOTE);
  83.  
  84.          WinMessageBox(HWND_DESKTOP, hwnd,
  85.                        pszText,
  86.                        "Message:",
  87.                        0, MB_OK | MB_INFORMATION);
  88.          WinPostMsg(hwnd, WM_CLOSE, NULL, NULL);
  89.          return 0;
  90.  
  91.       } /* WM_msg switch */
  92.    return WinDefWindowProc(hwnd, msg, mp1, mp2);
  93.    } /* MessageWndProc */
  94.  
  95.  
  96. /**
  97. *** ══════════════════════════════════════════════════════════════════════════
  98. ***    Message queue routines
  99. *** ══════════════════════════════════════════════════════════════════════════
  100. **/
  101.  
  102. USHORT ParseCommandLine(int argc, char *argv[], PSZ pszText)
  103.    {
  104.    USHORT i;    /* Loop index */
  105.  
  106.    _fstrcpy(pszText, "");
  107.    for (i = 1; i < argc; i++)
  108.       {
  109.       _fstrcat(pszText, argv[i]);
  110.       _fstrcat(pszText, " ");
  111.       }
  112.    return NO_ERROR;
  113.    } /* ParseCommandLine */
  114.