|
|
1.1.1.2 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: 1.1 root 12: /*---------------------------------------------------------------------------*\ 13: | RANDOM OBJECTS MODULE 14: \*---------------------------------------------------------------------------*/ 15: 16: #include <windows.h> 17: #include "gdidemo.h" 18: #include "draw.h" 19: 20: /*---------------------------------------------------------------------------*\ 21: | CREATE DRAW WINDOW PROCEDURE 22: \*---------------------------------------------------------------------------*/ 23: HWND FAR CreateDrawWindow(HWND hWndClient, int nItem) 24: { 25: HANDLE hInstance; 26: MDICREATESTRUCT mcs; 27: 28: 29: hInstance = GETINSTANCE(hWndClient); 30: 31: /* 32: ** Initialize the MDI create struct for creation of the 33: ** test window. 34: */ 35: mcs.szClass = DRAWCLASS; 36: mcs.szTitle = DRAWTITLE; 1.1.1.2 ! root 37: mcs.hOwner = hInstance; 1.1 root 38: mcs.x = CW_USEDEFAULT; 39: mcs.y = CW_USEDEFAULT; 40: mcs.cx = CW_USEDEFAULT; 41: mcs.cy = CW_USEDEFAULT; 1.1.1.2 ! root 42: mcs.style = 0l; 1.1 root 43: mcs.lParam = (LONG)nItem; 44: 1.1.1.2 ! root 45: return((HWND)SendMessage(hWndClient,WM_MDICREATE,0,(LONG)(LPMDICREATESTRUCT)&mcs)); 1.1 root 46: } 47: 48: 49: /*---------------------------------------------------------------------------*\ 50: | DRAW WINDOW PROCEDURE 51: \*---------------------------------------------------------------------------*/ 52: LONG APIENTRY DrawProc(HWND hWnd, UINT wMsg, WPARAM wParam, LONG lParam) 53: { 54: switch(wMsg) 55: { 56: case WM_CREATE: 57: DrawCreateProc(hWnd); 58: break; 59: 60: 61: case WM_COMMAND: 62: DrawCommandProc(hWnd,wParam,lParam); 63: break; 64: 65: 66: case WM_TIMER: 67: DrawObject(hWnd); 68: break; 69: 70: 71: case WM_PAINT: 72: DrawPaintProc(hWnd); 73: break; 74: 75: 76: case WM_DESTROY: 77: DrawDestroyProc(hWnd); 78: break; 79: 80: 81: default: 82: return(DefMDIChildProc(hWnd,wMsg,wParam,lParam)); 83: } 84: return(0l); 85: } 86: 87: 88: /*---------------------------------------------------------------------------*\ 89: | DRAW CREATE PROCEDURE 90: \*---------------------------------------------------------------------------*/ 91: BOOL DrawCreateProc(HWND hWnd) 92: { 93: PDRAWDATA pdd; 94: 95: 96: if(AllocWindowInfo(hWnd,sizeof(DRAWDATA))) 97: { 98: if(pdd = (PDRAWDATA)LockWindowInfo(hWnd)) 99: { 100: pdd->nObject = 0; 101: 102: UnlockWindowInfo(hWnd); 103: 104: SetTimer(hWnd,1,50,NULL); 105: return(TRUE); 106: } 107: FreeWindowInfo(hWnd); 108: } 109: return(FALSE); 110: } 111: 112: 113: /*---------------------------------------------------------------------------*\ 114: | DRAW COMMAND PROCEDURE 115: \*---------------------------------------------------------------------------*/ 116: BOOL DrawCommandProc(HWND hWnd, WPARAM wParam, LONG lParam) 117: { 118: hWnd = hWnd; 119: wParam = wParam; 120: lParam = lParam; 121: 122: return(TRUE); 123: } 124: 125: 126: /*---------------------------------------------------------------------------*\ 127: | DRAW PAINT PROCEDURE 128: \*---------------------------------------------------------------------------*/ 129: VOID DrawPaintProc(HWND hWnd) 130: { 131: HDC hDC; 132: PAINTSTRUCT ps; 133: 134: 135: if(hDC = BeginPaint(hWnd,&ps)) 136: EndPaint(hWnd,&ps); 137: 138: return; 139: } 140: 141: 142: /*---------------------------------------------------------------------------*\ 143: | DRAW DESTROY PROCEDURE 144: \*---------------------------------------------------------------------------*/ 145: VOID DrawDestroyProc(HWND hWnd) 146: { 147: KillTimer(hWnd,1); 148: FreeWindowInfo(hWnd); 149: return; 150: } 151: 152: 153: VOID DrawObject(HWND hWnd) 154: { 155: PDRAWDATA pdd; 156: RECT rect; 157: HDC hDC; 158: int x1,y1,x2,y2,x3,y3,x4,y4,r,g,b,nObject; 159: HBRUSH hBrush; 160: char szDebug[80]; 161: 162: 163: if(pdd = (PDRAWDATA)LockWindowInfo(hWnd)) 164: { 165: if(hDC = GetDC(hWnd)) 166: { 167: GetClientRect(hWnd,&rect); 168: 169: r = lRandom() % 255; 170: g = lRandom() % 255; 171: b = lRandom() % 255; 172: 173: if(hBrush = SelectObject(hDC,CreateSolidBrush(RGB(r,g,b)))) 174: { 175: x1 = lRandom() % rect.right; 176: y1 = lRandom() % rect.bottom; 177: x2 = lRandom() % rect.right; 178: y2 = lRandom() % rect.bottom; 179: x3 = lRandom() % rect.right; 180: y3 = lRandom() % rect.bottom; 181: x4 = lRandom() % rect.right; 182: y4 = lRandom() % rect.bottom; 183: 184: 185: nObject = lRandom() % 5; 186: 187: switch(nObject) 188: { 189: default: 190: case OBJ_RECTANGLE: 191: wsprintf(szDebug,"Rectangle(%d,%d,%d,%d)\n",x1,y1,x2,y2); 192: DEBUGOUT(szDebug); 193: Rectangle(hDC,x1,y1,x2,y2); 194: break; 195: 196: case OBJ_ELLIPSE: 197: wsprintf(szDebug,"Ellipse(%d,%d,%d,%d)\n",x1,y1,x2,y2); 198: DEBUGOUT(szDebug); 199: Ellipse(hDC,x1,y1,x2,y2); 200: break; 201: 202: 203: 204: case OBJ_ROUNDRECT: 205: wsprintf(szDebug,"RoundRect(%d,%d,%d,%d,%d,%d)\n",x1,y1,x2,y2,x3,y3); 206: DEBUGOUT(szDebug); 207: RoundRect(hDC,x1,y1,x2,y2,x3,y3); 208: break; 209: 210: case OBJ_CHORD: 211: wsprintf(szDebug,"Chord(%d,%d,%d,%d,%d,%d,%d,%d)\n",x1,y1,x2,y2,x3,y3,x4,y4); 212: DEBUGOUT(szDebug); 213: Chord(hDC,x1,y1,x2,y2,x3,y3,x4,y4); 214: break; 215: 216: case OBJ_PIE: 217: wsprintf(szDebug,"Pie(%d,%d,%d,%d,%d,%d,%d,%d)\n",x1,y1,x2,y2,x3,y3,x4,y4); 218: DEBUGOUT(szDebug); 219: Pie(hDC,x1,y1,x2,y2,x3,y3,x4,y4); 1.1.1.2 ! root 220: break; 1.1 root 221: 222: } 223: 224: DeleteObject(SelectObject(hDC,hBrush)); 225: } 226: ReleaseDC(hWnd,hDC); 227: } 228: UnlockWindowInfo(hWnd); 229: } 230: return; 231: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.