|
|
1.1 ! root 1: /*------------------------------------------- ! 2: CHECKER1.C -- Mouse Hit-Test Demo Program ! 3: -------------------------------------------*/ ! 4: ! 5: #define INCL_WIN ! 6: #include <os2.h> ! 7: ! 8: #define DIVISIONS 5 ! 9: ! 10: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ; ! 11: ! 12: int main (void) ! 13: { ! 14: static CHAR szClientClass [] = "Checker1" ; ! 15: static ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | ! 16: FCF_SIZEBORDER | FCF_MINMAX | ! 17: FCF_SHELLPOSITION | FCF_TASKLIST ; ! 18: HAB hab ; ! 19: HMQ hmq ; ! 20: HWND hwndFrame, hwndClient ; ! 21: QMSG qmsg ; ! 22: ! 23: hab = WinInitialize (0) ; ! 24: hmq = WinCreateMsgQueue (hab, 0) ; ! 25: ! 26: WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ; ! 27: ! 28: hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE, ! 29: &flFrameFlags, szClientClass, NULL, ! 30: 0L, NULL, 0, &hwndClient) ; ! 31: ! 32: while (WinGetMsg (hab, &qmsg, NULL, 0, 0)) ! 33: WinDispatchMsg (hab, &qmsg) ; ! 34: ! 35: WinDestroyWindow (hwndFrame) ; ! 36: WinDestroyMsgQueue (hmq) ; ! 37: WinTerminate (hab) ; ! 38: return 0 ; ! 39: } ! 40: ! 41: VOID DrawLine (HPS hps, LONG x1, LONG y1, LONG x2, LONG y2) ! 42: { ! 43: POINTL ptl ; ! 44: ! 45: ptl.x = x1 ; ptl.y = y1 ; GpiMove (hps, &ptl) ; ! 46: ptl.x = x2 ; ptl.y = y2 ; GpiLine (hps, &ptl) ; ! 47: } ! 48: ! 49: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2) ! 50: { ! 51: static BOOL fBlockState [DIVISIONS] [DIVISIONS] ; ! 52: static SHORT xBlock, yBlock ; ! 53: HPS hps ; ! 54: RECTL rcl ; ! 55: SHORT x, y ; ! 56: ! 57: switch (msg) ! 58: { ! 59: case WM_SIZE: ! 60: xBlock = SHORT1FROMMP (mp2) / DIVISIONS ; ! 61: yBlock = SHORT2FROMMP (mp2) / DIVISIONS ; ! 62: return 0 ; ! 63: ! 64: case WM_BUTTON1DOWN: ! 65: case WM_BUTTON1DBLCLK: ! 66: if (xBlock > 0 && yBlock > 0) ! 67: { ! 68: x = MOUSEMSG(&msg)->x / xBlock ; ! 69: y = MOUSEMSG(&msg)->y / yBlock ; ! 70: ! 71: if (x < DIVISIONS && y < DIVISIONS) ! 72: { ! 73: fBlockState [x][y] = !fBlockState [x][y] ; ! 74: ! 75: rcl.xRight = xBlock + (rcl.xLeft = x * xBlock) ; ! 76: rcl.yTop = yBlock + (rcl.yBottom = y * yBlock) ; ! 77: ! 78: WinInvalidateRect (hwnd, &rcl, FALSE) ; ! 79: } ! 80: else ! 81: WinAlarm (HWND_DESKTOP, WA_WARNING) ; ! 82: } ! 83: else ! 84: WinAlarm (HWND_DESKTOP, WA_WARNING) ; ! 85: ! 86: break ; // do default processing ! 87: ! 88: case WM_PAINT: ! 89: hps = WinBeginPaint (hwnd, NULL, NULL) ; ! 90: GpiErase (hps) ; ! 91: ! 92: if (xBlock > 0 && yBlock > 0) ! 93: for (x = 0 ; x < DIVISIONS ; x++) ! 94: for (y = 0 ; y < DIVISIONS ; y++) ! 95: { ! 96: rcl.xRight = xBlock + (rcl.xLeft = x * xBlock); ! 97: rcl.yTop = yBlock + (rcl.yBottom = y * yBlock); ! 98: ! 99: WinDrawBorder (hps, &rcl, 1, 1, ! 100: CLR_NEUTRAL, CLR_BACKGROUND, ! 101: DB_STANDARD | DB_INTERIOR) ; ! 102: ! 103: if (fBlockState [x][y]) ! 104: { ! 105: DrawLine (hps, rcl.xLeft, rcl.yBottom, ! 106: rcl.xRight, rcl.yTop) ; ! 107: ! 108: DrawLine (hps, rcl.xLeft, rcl.yTop, ! 109: rcl.xRight, rcl.yBottom) ; ! 110: } ! 111: } ! 112: WinEndPaint (hps) ; ! 113: return 0 ; ! 114: } ! 115: return WinDefWindowProc (hwnd, msg, mp1, mp2) ; ! 116: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.