|
|
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: * paths.c -- sample program demonstrating paths. 14: \**************************************************************************/ 15: 16: 17: #include <windows.h> 18: #include <string.h> 19: #include "paths.h" 20: 21: 22: /**************************************************************************\ 23: * 24: * function: WinMain() 25: * 26: * input parameters: c.f. generic sample 27: * 28: \**************************************************************************/ 1.1.1.2 ! root 29: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 1.1 root 30: LPSTR lpCmdLine, int nCmdShow) 31: { 32: HANDLE hInst; 33: HWND hwndMain; 34: MSG msg; 35: 36: UNREFERENCED_PARAMETER( lpCmdLine ); 37: 38: 39: /* Check for previous instance. If none, then register class. */ 40: if (!hPrevInstance) { 41: WNDCLASS wc; 42: 43: wc.style = CS_HREDRAW | CS_VREDRAW; 44: wc.lpfnWndProc = (WNDPROC)MainWndProc; 45: 46: wc.cbClsExtra = 0; 47: wc.cbWndExtra = 0; 48: wc.hInstance = hInstance; 49: wc.hIcon = LoadIcon(hInstance, "pathsIcon"); 50: wc.hCursor = LoadCursor(NULL, IDC_ARROW); 51: wc.hbrBackground = GetStockObject(LTGRAY_BRUSH); 52: wc.lpszMenuName = NULL; 53: wc.lpszClassName = "paths"; 54: 55: if (!RegisterClass(&wc)) return (FALSE); 56: } /* class registered o.k. */ 57: 58: 59: /* Create the main window. Return false if CreateWindow() fails */ 60: hInst = hInstance; 61: 62: hwndMain = CreateWindow( 63: "paths", 64: "Paths", 65: WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, 66: CW_USEDEFAULT, 67: CW_USEDEFAULT, 68: CW_USEDEFAULT, 69: CW_USEDEFAULT, 70: NULL, 71: NULL, 72: hInstance, 73: NULL); 74: 75: if (!hwndMain) return (FALSE); 76: ShowWindow(hwndMain, nCmdShow); 77: UpdateWindow(hwndMain); 78: 79: 80: /* Loop getting messages and dispatching them. */ 1.1.1.2 ! root 81: while (GetMessage(&msg,NULL, 0,0)) { 1.1 root 82: TranslateMessage(&msg); 83: DispatchMessage(&msg); 84: } 85: 86: return (msg.wParam); 87: } 88: 89: 90: 91: /**************************************************************************\ 92: * 93: * function: MainWndProc() 94: * 95: * input parameters: normal window procedure parameters. 96: * 97: * This is a very simple window. On create it creates pens to draw with. 98: * They are later destroyed at destroy time. The only interesting code 99: * is in the paint message. We draw 6 different paths into the client 100: * area demonstrating various features of paths. 101: * 102: * global variables: none. 103: \**************************************************************************/ 104: LONG APIENTRY MainWndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam) 105: { 106: static HANDLE hPenFill, hPenPath; 107: 108: 109: switch (message) { 110: 111: 112: /**********************************************************************\ 113: * WM_CREATE 114: * 115: * Create three pens for drawing with later. 116: \**********************************************************************/ 117: case WM_CREATE: 118: hPenPath = CreatePen (PS_SOLID, 2, (COLORREF) 0x01000005); 119: hPenFill = CreatePen (PS_SOLID, 1, (COLORREF) 0x01000002); 120: break; 121: 122: 123: /**********************************************************************\ 124: * WM_DESTROY 125: * 126: * Complement of the WM_CREATE message. Delete the pens that were 127: * created and then call postquitmessage. 128: \**********************************************************************/ 129: case WM_DESTROY: 130: DeleteObject (hPenFill); 131: DeleteObject (hPenPath); 132: 133: PostQuitMessage(0); 134: break; 135: 136: 137: /**********************************************************************\ 138: * WM_PAINT 139: * 140: * Query the client rectangle. Divide it into six sub rectangles 141: * (only actually compute the top left sixth). Now, set the origin 142: * for each one of these, write text describing the operation, and 143: * then stroke or fill or whatever the path. 144: \**********************************************************************/ 145: case WM_PAINT: { 146: HDC hdc; 147: PAINTSTRUCT ps; 148: RECT rect; 149: HRGN hrgn; 150: int i; 151: 152: hdc = BeginPaint(hwnd, &ps); 153: SetBkMode (hdc, TRANSPARENT); 154: 155: GetClientRect (hwnd, &rect); 156: rect.bottom /= 2; 157: rect.right /= 3; 158: SelectObject(hdc, hPenPath); 159: 160: /* 1. Just stroke the path */ 161: SetViewportOrgEx (hdc, 0, 0, NULL); 162: TextOut (hdc, 2, 10, STROKEPATH, sizeof (STROKEPATH)-1); 163: DrawPath(hdc, &rect); 164: StrokePath (hdc); 165: 166: 167: /* 2. Fill the path */ 168: SetViewportOrgEx (hdc, 0, rect.bottom, NULL); 169: TextOut (hdc, 2, 10, FILLPATH, sizeof (FILLPATH)-1); 170: DrawPath(hdc, &rect); 171: FillPath (hdc); 172: 173: /* 3. Stroke and fill the path */ 174: SetViewportOrgEx (hdc,rect.right, 0, NULL); 175: SetPolyFillMode (hdc, WINDING); 176: TextOut (hdc, 2, 10, STROKEANDFILLWIND, sizeof (STROKEANDFILLWIND)-1); 177: DrawPath(hdc, &rect); 178: StrokeAndFillPath (hdc); 179: 180: /* 4. Stroke and fill it again, but with different mode. */ 181: SetViewportOrgEx (hdc,rect.right, rect.bottom, NULL); 182: SetPolyFillMode (hdc, ALTERNATE); 183: TextOut (hdc, 2, 10, STROKEANDFILLALT, sizeof (STROKEANDFILLALT)-1); 184: DrawPath(hdc, &rect); 185: StrokeAndFillPath (hdc); 186: 187: 188: /* 5. Set the clipping region based on the path. */ 189: SetViewportOrgEx (hdc,rect.right*2, 0, NULL); 190: SetPolyFillMode (hdc, WINDING); 191: TextOut (hdc, 2, 10, CLIPPATHWIND, sizeof (CLIPPATHWIND)-1); 192: SelectObject(hdc, hPenFill); 193: DrawPath(hdc, &rect); 194: hrgn = PathToRegion(hdc); 195: SelectClipRgn (hdc, hrgn); 196: DeleteObject (hrgn); 197: MoveToEx (hdc, rect.right/2, rect.bottom/2, NULL); 198: for (i = 0; i < rect.right; i += 5) 199: AngleArc (hdc, rect.right/2, rect.bottom/2, i, (FLOAT)0.0, (FLOAT)360.0); 200: 201: /* 6. Set the clipping region based on the path, with different mode. */ 202: SetViewportOrgEx (hdc,rect.right*2, rect.bottom, NULL); 203: SetPolyFillMode (hdc, ALTERNATE); 204: /* clear the clip region so that TextOut() shows up. */ 205: ExtSelectClipRgn (hdc, NULL, RGN_COPY); 206: TextOut (hdc, 2, 10, CLIPPATHALT, sizeof (CLIPPATHALT)-1); 207: DrawPath(hdc, &rect); 208: hrgn = PathToRegion(hdc); 209: SelectClipRgn (hdc, hrgn); 210: DeleteObject (hrgn); 211: MoveToEx (hdc, rect.right/2, rect.bottom/2, NULL); 212: for (i = 0; i < rect.right; i += 5) 213: AngleArc (hdc, rect.right/2, rect.bottom/2, i, (FLOAT)0.0, (FLOAT)360.0); 214: 215: EndPaint (hwnd, &ps); 216: 1.1.1.2 ! root 217: } return 0; 1.1 root 218: 219: 1.1.1.2 ! root 220: } /* end switch */ ! 221: return (DefWindowProc(hwnd, message, wParam, lParam)); 1.1 root 222: } 223: 224: 225: 226: /**************************************************************************\ 227: * 228: * function: DrawPath() 229: * 230: * The path used here is a simple rectangle with an ellipse inside of it. 231: * The InflateRect() calls have nothing to do with the path, but are just 232: * used for convenience. 233: \**************************************************************************/ 234: void DrawPath(HDC hdc, PRECT prect) 235: { 236: RECT destRect; 237: 238: /* make a copy that we can modify with impunity. */ 239: CopyRect (&destRect, prect); 240: 241: BeginPath (hdc); 242: 243: InflateRect (&destRect, ((destRect.left- destRect.right)/5), 244: ((destRect.top- destRect.bottom)/5)); 245: 246: Rectangle (hdc, destRect.left, destRect.top, 247: destRect.right, destRect.bottom); 248: 249: InflateRect (&destRect, ((destRect.left- destRect.right)/4), 250: ((destRect.top- destRect.bottom)/4)); 251: 252: Ellipse (hdc, destRect.left, destRect.top, 253: destRect.right, destRect.bottom); 254: 255: EndPath (hdc); 256: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.