Annotation of pmsdk/samples/petzold/chap17/bigjob2.c, revision 1.1.1.1

1.1       root        1: /*-------------------------------------------------------
                      2:    BIGJOB2.C -- Timer approach to lengthy processing job
                      3:  --------------------------------------------------------*/
                      4: 
                      5: #define INCL_WIN
                      6: #include <os2.h>
                      7: #include "bigjob.h"
                      8: 
                      9: #define ID_TIMER 1
                     10: 
                     11: HAB  hab ;
                     12: 
                     13: int main (void)
                     14:      {
                     15:      static CHAR  szClientClass [] = "BigJob2" ;
                     16:      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
                     17:                                  FCF_SIZEBORDER    | FCF_MINMAX   |
                     18:                                  FCF_SHELLPOSITION | FCF_TASKLIST |
                     19:                                  FCF_MENU ;
                     20:      HMQ          hmq ;
                     21:      HWND         hwndFrame, hwndClient ;
                     22:      QMSG         qmsg ;
                     23: 
                     24:      hab = WinInitialize (0) ;
                     25:      hmq = WinCreateMsgQueue (hab, 0) ;
                     26: 
                     27:      WinRegisterClass (hab, szClientClass, ClientWndProc,
                     28:                        CS_SYNCPAINT | CS_SIZEREDRAW, 0) ;
                     29: 
                     30:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
                     31:                                      &flFrameFlags, szClientClass,
                     32:                                      " - The Timer",
                     33:                                      0L, NULL, ID_RESOURCE, &hwndClient) ;
                     34: 
                     35:      WinSendMsg (hwndFrame, WM_SETICON,
                     36:                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
                     37:                  NULL) ;
                     38: 
                     39:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
                     40:           WinDispatchMsg (hab, &qmsg) ;
                     41: 
                     42:      WinDestroyWindow (hwndFrame) ;
                     43:      WinDestroyMsgQueue (hmq) ;
                     44:      WinTerminate (hab) ;
                     45:      return 0 ;
                     46:      }
                     47: 
                     48: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
                     49:      {
                     50:      static double A ;
                     51:      static LONG   lRep, lCalcRep,
                     52:                    lRepAmts [] = { 10, 100, 1000, 10000, 100000 } ;
                     53:      static SHORT  sCurrentRep = IDM_10 ;
                     54:      static SHORT  sStatus = STATUS_READY ;
                     55:      static ULONG  ulElapsedTime ;
                     56: 
                     57:      switch (msg)
                     58:           {
                     59:           case WM_COMMAND:
                     60:                switch (COMMANDMSG(&msg)->cmd)
                     61:                     {
                     62:                     case IDM_10:
                     63:                     case IDM_100:
                     64:                     case IDM_1000:
                     65:                     case IDM_10000:
                     66:                     case IDM_100000:
                     67:                          CheckMenuItem (hwnd, sCurrentRep, FALSE) ;
                     68:                          sCurrentRep = COMMANDMSG(&msg)->cmd ;
                     69:                          CheckMenuItem (hwnd, sCurrentRep, TRUE) ;
                     70:                          return 0 ;
                     71: 
                     72:                     case IDM_START:
                     73:                          if (!WinStartTimer (hab, hwnd, ID_TIMER, 0))
                     74:                               {
                     75:                               WinAlarm (HWND_DESKTOP, WA_ERROR) ;
                     76:                               return 0 ;
                     77:                               }
                     78:                          EnableMenuItem (hwnd, IDM_START, FALSE) ;
                     79:                          EnableMenuItem (hwnd, IDM_ABORT, TRUE) ;
                     80: 
                     81:                          sStatus = STATUS_WORKING ;
                     82:                          WinInvalidateRect (hwnd, NULL, FALSE) ;
                     83: 
                     84:                          lCalcRep = lRepAmts [sCurrentRep - IDM_10] ;
                     85:                          ulElapsedTime = WinGetCurrentTime (hab) ;
                     86:                          A = 1.0 ;
                     87:                          lRep = 0 ;
                     88: 
                     89:                          return 0 ;
                     90: 
                     91:                     case IDM_ABORT:
                     92:                          WinStopTimer (hab, hwnd, ID_TIMER) ;
                     93: 
                     94:                          sStatus = STATUS_READY ;
                     95:                          WinInvalidateRect (hwnd, NULL, FALSE) ;
                     96: 
                     97:                          EnableMenuItem (hwnd, IDM_START, TRUE) ;
                     98:                          EnableMenuItem (hwnd, IDM_ABORT, FALSE) ;
                     99:                          return 0 ;
                    100:                     }
                    101:                break ;
                    102: 
                    103:           case WM_TIMER:
                    104:                A = Savage (A) ;
                    105: 
                    106:                if (++lRep == lCalcRep)
                    107:                     {
                    108:                     ulElapsedTime = WinGetCurrentTime (hab) -
                    109:                                         ulElapsedTime ;
                    110: 
                    111:                     WinStopTimer (hab, hwnd, ID_TIMER) ;
                    112: 
                    113:                     sStatus = STATUS_DONE ;
                    114:                     WinInvalidateRect (hwnd, NULL, FALSE) ;
                    115: 
                    116:                     EnableMenuItem (hwnd, IDM_START, TRUE) ;
                    117:                     EnableMenuItem (hwnd, IDM_ABORT, FALSE) ;
                    118:                     }
                    119:                return 0 ;
                    120: 
                    121:           case WM_PAINT:
                    122:                PaintWindow (hwnd, sStatus, lCalcRep, ulElapsedTime) ;
                    123:                return 0 ;
                    124: 
                    125:           case WM_DESTROY:
                    126:                if (sStatus == STATUS_WORKING)
                    127:                     WinStopTimer (hab, hwnd, ID_TIMER) ;
                    128:                return 0 ;
                    129:           }
                    130:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
                    131:      }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.