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