home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / WLADD.ZIP / WLADD.C next >
Text File  |  1990-07-31  |  3KB  |  118 lines

  1. #define INCL_WIN
  2. #include <os2.h>
  3. #include <string.h>
  4. #include "os2supt.h"
  5. #include "wladd.h"
  6.  
  7. /* Global variables */
  8.  
  9. HAB           hab;         /* Handle to an anchor block */
  10.  
  11. /**
  12. *** ═════════════════════════════════════════════════════════════════════════
  13. **/
  14.  
  15. int main(int argc, char *argv[])
  16.    {
  17.    static ULONG  flFrameFlags = FCF_SHELLPOSITION |
  18.                                 FCF_TASKLIST      ;
  19.  
  20.    HMQ           hmq;         /* Handle to a message queue */
  21.    HWND          hwndFrame;   /* Handle to the frame window */
  22.    QMSG          qmsg;        /* A queued message */
  23.  
  24.    /* Check for a filename from the command line */
  25.  
  26.    hab = WinInitialize(0);    /* Initialize the window routines */
  27.    hmq = WinCreateMsgQueue(hab,0);  /* Create the PM message queue */
  28.  
  29.    WinRegisterClass(hab, CLIENTCLASS, ClientWindowProc, 0L, 0);
  30.  
  31.    hwndFrame = WinCreateWindow(HWND_DESKTOP, CLIENTCLASS, NULL, 0L,
  32.                                0, 0, 0, 0, HWND_DESKTOP, HWND_BOTTOM,
  33.                                0, NULL, 0);
  34.  
  35.    while(WinGetMsg(hab, &qmsg, NULL, 0, 0))
  36.       WinDispatchMsg(hab,&qmsg);
  37.  
  38.    WinDestroyWindow(hwndFrame);
  39.    WinDestroyMsgQueue(hmq);
  40.    WinTerminate(hab);
  41.    return 0;
  42.    } /* Main */
  43.  
  44. /**
  45. *** ═════════════════════════════════════════════════════════════════════════
  46. ***     Primary dialog procedure
  47. *** ═════════════════════════════════════════════════════════════════════════
  48. **/
  49.  
  50. MRESULT EXPENTRY ClientWindowProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  51.    {
  52.    static HWND     hwndWL;           /* Handle to the W L program        */
  53.    static USHORT   usTimerCount = 0; /* Number of timer pops             */
  54.  
  55.    switch(msg)
  56.       {
  57.       case WM_CREATE:
  58.          WinAlarm(HWND_DESKTOP,WA_NOTE);
  59.          if (!WinStartTimer(hab, hwnd, TIMER, 3000))
  60.             {
  61.             ErrorHandler(hwnd, CLIENTCLASS, NULL, 0, UERROR_NO_TIMERS, ERRTYPE_USER, 0);
  62.             WinPostMsg(hwnd,WM_CLOSE,NULL,NULL);
  63.             }
  64.          break;
  65.  
  66.       case WM_TIMER:
  67.          WinAlarm(HWND_DESKTOP,WA_NOTE);
  68.          usTimerCount++;
  69.          if (usTimerCount > 5)
  70.             {
  71.             WinStopTimer(hab, hwnd, TIMER);
  72.             ErrorHandler(hwnd, CLIENTCLASS, NULL, 0, UERROR_NO_WINDOW_HANDLE, ERRTYPE_USER, 0);
  73.             WinPostMsg(hwnd,WM_CLOSE,NULL,NULL);
  74.             }
  75.  
  76.          if ((hwndWL = FindWL(HWND_DESKTOP)) != NULL)
  77.             {
  78.             WinStopTimer(hab, hwnd, TIMER);
  79.             AddToTaskList(hwndWL, CLIENTCLASS);
  80.             WinPostMsg(hwnd,WM_CLOSE,NULL,NULL);
  81.             }
  82.          break;
  83.  
  84.       } /* WM_msg switch */
  85.  
  86.    return WinDefWindowProc(hwnd, msg, mp1, mp2);
  87.    } /* ClientWindowProc */
  88.  
  89.  
  90.  
  91. HWND FindWL(HWND hwnd)
  92.    {
  93.    HWND   hwndNext;     /* Handle to a window frame      */
  94.    CHAR   szTemp[8];    /* Title of the window frame     */
  95.    HENUM  hEnum;        /* Handle to an enumeration list */
  96.  
  97.    /* Enumerate the Windows on the desktop */
  98.  
  99.    hEnum = WinBeginEnumWindows(hwnd);
  100.    while ((hwndNext = WinGetNextWindow(hEnum)) != NULL)
  101.       {
  102.  
  103.       /* Unlock the Window */
  104.  
  105.       WinLockWindow(hwndNext,FALSE);
  106.  
  107.       /* Get the name of the window */
  108.  
  109.       WinQueryWindowText(hwndNext,8,szTemp);
  110.  
  111.       if (!strcmp(szTemp,"W L"))
  112.          return hwndNext;
  113.  
  114.       } /* end While */
  115.    WinEndEnumWindows(hEnum);
  116.    return NULL;
  117.    }
  118.