|
|
1.1 root 1: /*-------------------------------------------------------
2: BIGJOB1.C -- Naive 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 [] = "BigJob1" ;
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,
26: CS_SYNCPAINT | CS_SIZEREDRAW, 0) ;
27:
28: hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
29: &flFrameFlags, szClientClass,
30: " - The Bad Program",
31: 0L, NULL, ID_RESOURCE, &hwndClient) ;
32:
33: WinSendMsg (hwndFrame, WM_SETICON,
34: WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
35: NULL) ;
36:
37: while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
38: WinDispatchMsg (hab, &qmsg) ;
39:
40: WinDestroyWindow (hwndFrame) ;
41: WinDestroyMsgQueue (hmq) ;
42: WinTerminate (hab) ;
43: return 0 ;
44: }
45:
46: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
47: {
48: static LONG lCalcRep, lRepAmts [] = { 10, 100, 1000, 10000, 100000 } ;
49: static SHORT sCurrentRep = IDM_10 ;
50: static SHORT sStatus = STATUS_READY ;
51: static ULONG ulElapsedTime ;
52: double A ;
53: LONG lRep ;
54:
55: switch (msg)
56: {
57: case WM_COMMAND:
58: switch (COMMANDMSG(&msg)->cmd)
59: {
60: case IDM_10:
61: case IDM_100:
62: case IDM_1000:
63: case IDM_10000:
64: case IDM_100000:
65: CheckMenuItem (hwnd, sCurrentRep, FALSE) ;
66: sCurrentRep = COMMANDMSG(&msg)->cmd ;
67: CheckMenuItem (hwnd, sCurrentRep, TRUE) ;
68: return 0 ;
69:
70: case IDM_START:
71: EnableMenuItem (hwnd, IDM_START, FALSE) ;
72: EnableMenuItem (hwnd, IDM_ABORT, TRUE) ;
73:
74: sStatus = STATUS_WORKING ;
75: WinInvalidateRect (hwnd, NULL, FALSE) ;
76:
77: WinSetPointer (HWND_DESKTOP,
78: WinQuerySysPointer (HWND_DESKTOP,
79: SPTR_WAIT, FALSE)) ;
80:
81: if (WinQuerySysValue (HWND_DESKTOP, SV_MOUSEPRESENT)
82: == 0)
83: WinShowPointer (HWND_DESKTOP, TRUE) ;
84:
85: lCalcRep = lRepAmts [sCurrentRep - IDM_10] ;
86: ulElapsedTime = WinGetCurrentTime (hab) ;
87:
88: for (A = 1.0, lRep = 0 ; lRep < lCalcRep ; lRep++)
89: A = Savage (A) ;
90:
91: ulElapsedTime = WinGetCurrentTime (hab) -
92: ulElapsedTime ;
93:
94: if (WinQuerySysValue (HWND_DESKTOP, SV_MOUSEPRESENT)
95: == 0)
96: WinShowPointer (HWND_DESKTOP, FALSE) ;
97:
98: WinSetPointer (HWND_DESKTOP,
99: WinQuerySysPointer (HWND_DESKTOP,
100: SPTR_ARROW, FALSE)) ;
101: sStatus = STATUS_DONE ;
102: WinInvalidateRect (hwnd, NULL, FALSE) ;
103:
104: EnableMenuItem (hwnd, IDM_START, TRUE) ;
105: EnableMenuItem (hwnd, IDM_ABORT, FALSE) ;
106: return 0 ;
107:
108: case IDM_ABORT: // Not much we can do here
109: return 0 ;
110: }
111: break ;
112:
113: case WM_PAINT:
114: PaintWindow (hwnd, sStatus, lCalcRep, ulElapsedTime) ;
115: return 0 ;
116: }
117: return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
118: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.