home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PMWALKER.ZIP / WALKER.C < prev    next >
C/C++ Source or Header  |  1989-08-14  |  3KB  |  114 lines

  1. /* WALKER.C - Sample Animated Icon Program                     */
  2. /* Copyright (C) Lee S. Fields, 1989                         */
  3.  
  4.  
  5. #define INCL_WIN
  6.  
  7. #include <os2.h>
  8. #include <stddef.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include "walker.h"
  13.  
  14. /* declare functions to enforce type checking */
  15. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM);
  16.  
  17. /* window anchor block handle */
  18. HAB hab;
  19.  
  20. HMQ hmq;                   /* message queue handle */
  21. HWND hwndClient, hwndFrame;           /* window handles */
  22. QMSG qmsg;                   /* message queue structure */
  23.  
  24. /* Common string prefixes */
  25. CHAR szCaption[80] = "Walker";
  26.  
  27.  
  28. /* main function setup to accept command line parameters */
  29. void main (void)
  30. {
  31.     static CHAR szClientClass[] = "Walker";    /* window class name */
  32.  
  33.  /* start frame with icon, system menu and titlebar                 */
  34.  /* tasklist flag creates problem when selecting from tas     */
  35.     ULONG flFrameFlags = FCF_ICON | FCF_SYSMENU | FCF_TITLEBAR;
  36.  
  37.  /* start frame style as visible and minimized */
  38.     ULONG flFrameStyle = WS_VISIBLE | WS_MINIMIZED;
  39.  
  40.  
  41.     hab = WinInitialize (0);           /* initialize window anchor block
  42.                         * handle */
  43.     hmq = WinCreateMsgQueue (hab, 0);  /* create window message queue */
  44.  
  45.     WinRegisterClass (hab, szClientClass, ClientWndProc, 0L, 0);    /* register window class */
  46.  
  47.     hwndFrame = WinCreateStdWindow (HWND_DESKTOP,    /* parent window handle */
  48.                     flFrameStyle,    /* window frame style */
  49.                     &flFrameFlags,    /* window control flags */
  50.                     szClientClass,    /* window class name */
  51.                     szCaption,    /* title bar text */
  52.                     0L,/* client window style */
  53.                     NULL,    /* resources in .exe */
  54.                     IDP_STEP1,    /* icon resource id */
  55.                     &hwndClient);    /* pointer to client
  56.                              * window handler */
  57.  
  58.  /* Process messages, no preprocessing required so just dispatch them */
  59.  /* Exit when WM_QUIT message returns FALSE */
  60.     while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  61.     WinDispatchMsg (hab, &qmsg);
  62.  
  63.     WinDestroyWindow (hwndFrame);      /* destroy the window */
  64.     WinDestroyMsgQueue (hmq);           /* destroy the message queue */
  65.     WinTerminate (hab);               /* destroy the anchor block handle */
  66.     return 0;
  67. }
  68.  
  69.  
  70.  
  71. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  72. {
  73.     static HPOINTER step[IDP_STEP4];
  74.  
  75.     static SHORT counter = IDP_STEP1;
  76.  
  77.  /* process messages */
  78.     switch (msg)
  79.     {
  80.     /* Window is being created */
  81.     case WM_CREATE:
  82.         for (counter = IDP_STEP1; counter <= IDP_STEP4; counter++)
  83.             step[counter] = WinLoadPointer (HWND_DESKTOP, NULL, counter);
  84.         
  85.         if (!WinStartTimer (hab, hwnd, ID_TIMER, 333))
  86.         {
  87.             WinMessageBox (HWND_DESKTOP, hwnd, "Too many timers",
  88.                    szCaption, 0, MB_OK | MB_ICONEXCLAMATION);
  89.             WinPostMsg (hwnd, WM_QUIT, 0L, 0L);    /* send message to exit
  90.                              * program */
  91.         }
  92.         return 0;
  93.  
  94.     case WM_TIMER:
  95.         if (counter > IDP_STEP4)
  96.             counter = IDP_STEP1;
  97.  
  98.         WinSendMsg (hwndFrame, WM_SETICON, step[counter], NULL);
  99.         WinInvalidateRect (hwndFrame, NULL, FALSE);
  100.  
  101.  
  102.         counter++;
  103.         return 0;
  104.  
  105.  
  106.     case WM_DESTROY:
  107.         WinStopTimer (hab, hwnd, ID_TIMER);
  108.         for (counter = IDP_STEP1; counter <= IDP_STEP4; counter++)
  109.             WinDestroyPointer (step[counter]);
  110.         return 0;
  111.     }
  112.     return WinDefWindowProc (hwnd, msg, mp1, mp2);
  113. }
  114.