|
|
1.1.1.3 ! 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: * streblt.c -- sample program demonstrating StretchBlt() 14: * 15: * design: There is one main window with one dialog box streblted to fill 16: * the top of it. The parameters for the StretchBlt() are stored in the 17: * entry fields of this dialog box. The user may change these values and 18: * see the effect on the blt. The top dialog also offers a chance to set 19: * the streblt blt mode, to select pattern brushes for the hdc, and to 20: * select from standard raster operations 21: \**************************************************************************/ 22: 23: 24: #include <windows.h> 25: #include <commdlg.h> 26: #include <math.h> 27: #include <string.h> 28: #include <stdio.h> 29: #include "streblt.h" 30: #include "track.h" 31: #include "bitmap.h" 32: 33: 34: /* Global variables */ 35: HANDLE hInst; 36: HWND hwndMain, hwndDlg; 37: 38: PTrackObject ptoSrc, ptoDest = NULL; 39: HDC hdcSrc, hdcDest; 40: HBITMAP hbmSrc = NULL; 41: 42: #define NONE -1 43: int strebltMode = NONE; 44: int iPatternBrush = NONE; 45: 46: 47: 48: 49: 50: /**************************************************************************\ 51: * 52: * function: WinMain() 53: * 54: * input parameters: c.f. generic sample 55: * 56: \**************************************************************************/ 1.1.1.3 ! root 57: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 1.1 root 58: LPSTR lpCmdLine, int nCmdShow) 59: { 60: MSG msg; 61: RECT rect; 62: HANDLE haccel; 63: 64: UNREFERENCED_PARAMETER( lpCmdLine ); 65: 66: 67: /* Check for previous instance. If none, then register class. */ 68: if (!hPrevInstance) { 69: WNDCLASS wc; 70: 1.1.1.3 ! root 71: wc.style = 0; 1.1 root 72: wc.lpfnWndProc = (WNDPROC)MainWndProc; 73: 74: wc.cbClsExtra = 0; 75: wc.cbWndExtra = 0; 76: wc.hInstance = hInstance; 77: wc.hIcon = LoadIcon(hInstance, "strebltIcon"); 78: wc.hCursor = LoadCursor(NULL, IDC_ARROW); 79: wc.hbrBackground = GetStockObject(LTGRAY_BRUSH); 80: wc.lpszMenuName = NULL; 81: wc.lpszClassName = "streblt"; 82: 83: if (!RegisterClass(&wc)) return (FALSE); 84: } /* class registered o.k. */ 85: 86: 87: /* Create the main window. Return false if CreateWindow() fails */ 88: hInst = hInstance; 89: 90: hwndMain = CreateWindow( 91: "streblt", 92: "StretchBlt()", 93: WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, 94: CW_USEDEFAULT, 95: CW_USEDEFAULT, 96: CW_USEDEFAULT, 97: CW_USEDEFAULT, 98: NULL, 99: NULL, 100: hInstance, 101: NULL); 102: 103: if (!hwndMain) return (FALSE); 104: 105: 106: /* create the top dialog as a child of the main window. */ 1.1.1.2 root 107: hwndDlg = CreateDialog (hInst, "strebltDlg", hwndMain, (DLGPROC)DlgProc); 1.1 root 108: 109: /* Send main window a WM_SIZE message so that it will size the top 110: * dialog correctly. Also, force a repaint of the main window 111: * now that the dialog is there and we can draw the arc. 112: */ 113: GetClientRect (hwndMain, &rect); 114: SendMessage (hwndMain, WM_SIZE, 0, (rect.right - rect.left)); 115: ShowWindow (hwndDlg, SW_SHOW); 116: ShowWindow(hwndMain, nCmdShow); 117: 118: 119: /* Load the accelerator table that provides clipboard support. */ 120: haccel = LoadAccelerators (hInst, "bltAccel"); 121: 122: 123: /* Loop getting messages and dispatching them. */ 1.1.1.3 ! root 124: while (GetMessage(&msg,NULL, 0,0)) { 1.1 root 125: if (!TranslateAccelerator(hwndMain, haccel, &msg)) 126: if (!IsDialogMessage (hwndDlg, &msg)) { 127: DispatchMessage(&msg); 128: } 129: } 130: 1.1.1.3 ! root 131: return (msg.wParam); /* Returns the value from PostQuitMessage */ 1.1 root 132: } 133: 134: 135: 136: 137: /**************************************************************************\ 138: * 139: * function: MainWndProc() 140: * 141: * input parameters: normal window procedure parameters. 142: * 143: * This is the main window window procedure. Allocate needed structures 144: * at create time and free them at destroy time. Pass the mouse messages 145: * down to the track objects when appropriate. Size the top dialog on 146: * size messages. The window is painted in two halfs. One for the source 147: * region and one for the destination region. The StretchBlt() call is 148: * separated out as a user message so that the call can be made without 149: * erasing the whole window. 150: * 151: * global variables: 152: * hwndDlg - dialog with entry fields containing arc parameters. 153: * ptoSrc - pointer to the source track object 154: * hdcSrc - device context for the right half the window. 155: * ptoDest - pointer to the destination track object 156: * hdcDest - device context for the left half the window. 157: * hbmSrc - bitmap handle for the source bitmap. 158: * 159: * strebltMode - Selection from combo box, to be used in SetStretchBltMode() 160: * iPatternBrush - Selection from combo box, set into the hdc. 161: \**************************************************************************/ 162: LONG APIENTRY MainWndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam) 163: { 164: static int miniWidth; 165: static RECT rect; 166: char buffer[MAXCHARS]; 167: static HANDLE hPenGrid, hPenSeparator; 168: 169: 170: switch (message) { 171: 172: /**********************************************************************\ 173: * WM_CREATE 174: * 175: * Get the two hdc's for this window, allocate two track objects, 176: * and then create two pens to be used when painting the windows. 177: \**********************************************************************/ 178: case WM_CREATE: 179: hdcSrc = GetDC (hwnd); 180: hdcDest = GetDC (hwnd); 181: 1.1.1.3 ! root 182: ptoDest = doTrackObject (NULL, TROB_NEW, hwnd,0); ! 183: ptoSrc = doTrackObject (NULL, TROB_NEW, hwnd,0); 1.1 root 184: 185: hPenGrid = CreatePen (PS_SOLID, 1, GRIDCOLOR); 186: hPenSeparator = CreatePen (PS_SOLID, 2*SEPARATORWIDTH, (COLORREF) 0x01000000); 187: break; 188: 189: 190: /**********************************************************************\ 191: * WM_DESTROY 192: * 193: * Complement of WM_CREATE. Free up all of the HDCs, send all of the 194: * track objects their delete messages, then call PostQuitMessage. 195: \**********************************************************************/ 196: case WM_DESTROY: 197: ReleaseDC (hwnd, hdcSrc ); 198: ReleaseDC (hwnd, hdcDest); 1.1.1.3 ! root 199: doTrackObject (ptoDest, TROB_DELETE, hwnd,0); ! 200: doTrackObject (ptoSrc , TROB_DELETE, hwnd,0); 1.1 root 201: 202: DeleteObject(hPenGrid); 203: DeleteObject(hPenSeparator); 204: 205: PostQuitMessage(0); 206: break; 207: 208: 209: 210: /**********************************************************************\ 211: * WM_SIZE 212: * 213: * streblt the top dialog to fill the width of the main window. 214: * Adjust the viewport origins of the 4 HDCs. 215: * Set the clip regions of the 4 HDCs. 216: \**********************************************************************/ 217: case WM_SIZE: { 218: HRGN hrgn; 219: 1.1.1.3 ! root 220: SetWindowPos (hwndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0); 1.1 root 221: 222: GetClientRect (hwndMain, &rect); 223: miniWidth = rect.right/2; 224: 225: SetViewportOrgEx (hdcDest, 0, DIALOGHEIGHT, NULL); 226: SetViewportOrgEx (ptoDest->hdc, 0, DIALOGHEIGHT, NULL); 227: SetViewportOrgEx (hdcSrc, miniWidth, DIALOGHEIGHT, NULL); 228: SetViewportOrgEx (ptoSrc->hdc, miniWidth, DIALOGHEIGHT, NULL); 229: 230: ptoDest->rectClip.left = 0; 231: ptoDest->rectClip.top = DIALOGHEIGHT; 232: ptoDest->rectClip.right = miniWidth-2*SEPARATORWIDTH; 233: ptoDest->rectClip.bottom = rect.bottom; 234: hrgn = CreateRectRgnIndirect (&ptoDest->rectClip); 235: SelectClipRgn (hdcDest, hrgn); 236: SelectClipRgn (ptoDest->hdc, hrgn); 237: DeleteObject (hrgn); 238: 239: ptoSrc->rectClip.left = miniWidth; 240: ptoSrc->rectClip.top = DIALOGHEIGHT; 241: ptoSrc->rectClip.right = 2*miniWidth; 242: ptoSrc->rectClip.bottom = rect.bottom; 243: hrgn = CreateRectRgnIndirect (&ptoSrc->rectClip); 244: SelectClipRgn (hdcSrc, hrgn); 245: SelectClipRgn (ptoSrc->hdc, hrgn); 246: DeleteObject (hrgn); 247: 248: SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD)hdcDest, (LONG)ptoDest); 249: SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD)hdcSrc, (LONG)ptoSrc); 250: 251: InvalidateRect (hwnd, NULL, TRUE); 252: } break; 253: 254: 255: 256: /**********************************************************************\ 257: * WM_PAINT 258: * 259: * miniWidth, rect -- set by WM_SIZE message. 260: * 261: * First shift the viewport origin down so that 0,0 is the top left 262: * most visible point (out from underneath the top dialog). Second, 263: * draw the grid with wider lines on the axes. Finally, read the 264: * values out of the top dialog, do elementary validation, and then 265: * try to call StretchBlt() with the values. 266: \**********************************************************************/ 267: case WM_PAINT: { 268: HDC hdc; 269: PAINTSTRUCT ps; 270: 271: hdc = BeginPaint(hwnd, &ps); 272: 273: /* Draw Separator lines for the three miniareas */ 274: SelectObject(hdc, hPenSeparator); 275: MoveToEx (hdc, miniWidth-SEPARATORWIDTH,0, NULL); 276: LineTo (hdc, miniWidth-SEPARATORWIDTH , rect.bottom); 277: 278: /* Grid the 2 HDCs */ 279: SelectObject (hdcSrc, hPenGrid); 280: DrawGrids (hdcSrc, miniWidth, rect.bottom); 281: SelectObject (hdcDest, hPenGrid); 282: DrawGrids (hdcDest, miniWidth, rect.bottom); 283: 284: /* if a source bitmap has been selected, draw it. */ 285: if (hbmSrc) DrawBitmap (hdcSrc, hbmSrc); 286: 287: /* paint the source track object on top of the bitmap */ 1.1.1.3 ! root 288: doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0); 1.1 root 289: 290: /* make the call to StretchBlt() for the left half the window */ 291: SendMessage (hwnd, WM_STRETCHBLT, 0,0); 292: 293: EndPaint (hwnd, &ps); 294: } return FALSE; 295: 296: 297: 298: /**********************************************************************\ 299: * WM_STRETCHBLT 300: * 301: * Separate out the StretchBlt() call from the rest of the WM_PAINT 302: * case in this user message. In this way, we can blt() without erasing 303: * and/or repaint all of the rest of the window. Send this message when 304: * only the blt() should be done. Invalidate the left half of the window 305: * when it should be erased, re-grided, and then blt()ed. 306: \**********************************************************************/ 307: case WM_STRETCHBLT: { 308: int X, Y, nWidth, nHeight, 309: XSrc, YSrc, nSrcWidth, nSrcHeight; 310: LONG rop, ropByte; 311: BOOL success; 312: 313: /* erase source track object, or top left sides will show up in blt. */ 1.1.1.3 ! root 314: doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0); 1.1 root 315: 316: /* Get the parameters out of the top dialog box and call StretchBlt */ 317: if (IsWindow(hwndDlg)) { 318: 319: X = GetDlgItemInt(hwndDlg, DID_X, &success, TRUE); 320: Y = GetDlgItemInt(hwndDlg, DID_Y, &success, TRUE); 321: nWidth = GetDlgItemInt(hwndDlg, DID_WIDTH, &success, TRUE); 322: nHeight = GetDlgItemInt(hwndDlg, DID_HEIGHT, &success, TRUE); 323: XSrc = GetDlgItemInt(hwndDlg, DID_XSRC, &success, TRUE); 324: YSrc = GetDlgItemInt(hwndDlg, DID_YSRC, &success, TRUE); 325: nSrcWidth = GetDlgItemInt(hwndDlg, DID_SRCWIDTH, &success, TRUE); 326: nSrcHeight = GetDlgItemInt(hwndDlg, DID_SRCHEIGHT, &success, TRUE); 327: 328: /* get high order ROP byte and shift left by two bytes. */ 329: GetDlgItemText(hwndDlg, DID_ROP0, buffer, MAXCHARS); 330: sscanf (buffer, "%lx", &ropByte); 331: rop = ropByte * 256 * 256; 332: 333: /* get the next ROP byte and shift left by one byte. */ 334: GetDlgItemText(hwndDlg, DID_ROP1, buffer, MAXCHARS); 335: sscanf (buffer, "%lx", &ropByte); 336: rop += ropByte * 256; 337: 338: /* finally, get the low order ROP byte. */ 339: GetDlgItemText(hwndDlg, DID_ROP2, buffer, MAXCHARS); 340: sscanf (buffer, "%lx", &ropByte); 341: rop += ropByte; 342: 343: /* set streblt mode. (user selects via combo box.) */ 344: if (strebltMode != NONE) 345: SetStretchBltMode (hdcDest, strebltMode); 346: 347: /* select the pattern brush. (user selects via combo box.) */ 348: if (iPatternBrush != NONE) 349: SelectObject (hdcDest, GetStockObject (iPatternBrush)); 350: 351: /**********************************************************/ 352: /**********************************************************/ 353: StretchBlt (hdcDest, X, Y, nWidth, nHeight, 354: hdcSrc, XSrc, YSrc, nSrcWidth, nSrcHeight, rop); 355: /**********************************************************/ 356: /**********************************************************/ 357: } 358: 359: /* redraw source track object which was erased temporarily. */ 1.1.1.3 ! root 360: doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0); 1.1 root 361: } break; 362: 363: 364: 365: /**********************************************************************\ 366: * WM_LBUTTONDOWN 367: * On button down messages, hittest on the track object, and if 368: * it returns true, then send these messages to the track object. 369: \**********************************************************************/ 370: case WM_LBUTTONDOWN: 371: if (doTrackObject(ptoDest, TROB_HITTEST, hwnd, lParam)) 372: doTrackObject(ptoDest, message, hwnd, lParam); 373: else if (doTrackObject(ptoSrc, TROB_HITTEST, hwnd, lParam)) 374: doTrackObject(ptoSrc, message, hwnd, lParam); 375: break; 376: 377: 378: 379: /**********************************************************************\ 380: * WM_LBUTTONUP 381: * If the track object is in a "tracking mode" then send it this message. 382: * For the source track object, just send a STRETCHBLT message. 383: * For the dest. track object, invalidate the left half causing erase. 384: \**********************************************************************/ 385: case WM_LBUTTONUP: 386: if (ptoDest->Mode) { 387: doTrackObject(ptoDest, message, hwnd, lParam); 388: SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD) hdcDest, (LONG) ptoDest); 389: InvalidateRect (hwndMain, &ptoSrc->rectClip, TRUE); 390: InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE); 391: } 392: if (ptoSrc->Mode) { 393: doTrackObject(ptoSrc, message, hwnd, lParam); 394: SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD) hdcSrc, (LONG) ptoSrc); 395: PostMessage (hwndMain, WM_STRETCHBLT, 0,0); 396: } 397: break; 398: 399: 400: /**********************************************************************\ 401: * MW_MOUSEMOVE 402: * If the track object is in a "tracking mode" then send it these messages. 403: * Also, update the coordinates in the top dialog box. 404: \**********************************************************************/ 405: case WM_MOUSEMOVE: 406: if (ptoDest->Mode) { 407: doTrackObject(ptoDest, message, hwnd, lParam); 408: SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD) hdcDest, (LONG) ptoDest); 409: } 410: if (ptoSrc->Mode) { 411: doTrackObject(ptoSrc, message, hwnd, lParam); 412: SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD) hdcSrc, (LONG) ptoSrc); 413: } 414: break; 415: 416: 417: 418: 419: 420: /**********************************************************************\ 421: * Accelerator & clipboard support. 422: * 423: * Certain key strokes (c.f. *.rc) will cause the following WM_COMMAND 424: * messages. In response the app will copy a bitmap into the clipboard 425: * or paste down from it. In both cases, it is necessary to create a 426: * new bitmap since a bitmap in the clipboard belongs to the clipboard 427: * and not to the application. 428: \**********************************************************************/ 429: case WM_COMMAND: 430: switch (LOWORD(wParam)) { 431: HBITMAP hbmCompat, hbmOld; 432: HDC hdcCompat; 433: 434: /******************************************************************\ 435: * WM_COMMAND, AID_COPY 436: * 437: * Create a new bitmap, copy the destination HDC bits into it, 438: * and send the new bitmap to the clipboard. 439: \******************************************************************/ 440: case AID_COPY: { 441: int X,Y, nWidth, nHeight; 442: BOOL success; 443: 444: X = GetDlgItemInt(hwndDlg, DID_X, &success, TRUE); 445: Y = GetDlgItemInt(hwndDlg, DID_Y, &success, TRUE); 446: nWidth = GetDlgItemInt(hwndDlg, DID_WIDTH, &success, TRUE); 447: nHeight = GetDlgItemInt(hwndDlg, DID_HEIGHT, &success, TRUE); 448: 449: 450: hdcCompat = CreateCompatibleDC(hdcDest); 451: hbmCompat = CreateCompatibleBitmap (hdcDest, nWidth, nHeight); 452: hbmOld = SelectObject(hdcCompat,hbmCompat); 453: 454: BitBlt (hdcCompat, 0,0,nWidth, nHeight, hdcDest, X,Y, SRCCOPY ); 455: 456: SelectObject(hdcCompat,hbmOld); 457: DeleteDC(hdcCompat); 458: 459: OpenClipboard (hwnd); 460: SetClipboardData (CF_BITMAP,hbmCompat); 461: CloseClipboard (); 462: 463: DeleteObject (hbmCompat); 464: 465: } break; 466: 467: 468: /******************************************************************\ 469: * WM_COMMAND, AID_PASTE 470: * 471: * Get bitmap handle from clipboard, create a new bitmap, draw 472: * the clipboard bitmap into the new one, and store the new 473: * handle in the global hbmSrc. 474: \******************************************************************/ 475: case AID_PASTE: { 476: HBITMAP hbm; 477: BITMAP bm; 478: 479: OpenClipboard (hwnd); 480: if ( hbm = GetClipboardData (CF_BITMAP)) { 481: DeleteObject (hbmSrc); 482: 483: GetObject (hbm, sizeof(BITMAP), &bm); 484: 485: hdcCompat = CreateCompatibleDC(hdcDest); 486: hbmCompat = CreateCompatibleBitmap (hdcDest, bm.bmWidth, bm.bmHeight); 487: hbmOld = SelectObject(hdcCompat,hbmCompat); 488: 489: DrawBitmap (hdcCompat, hbm); 490: 491: SelectObject(hdcCompat,hbmOld); 492: DeleteDC(hdcCompat); 493: 494: hbmSrc = hbmCompat; 495: 496: InvalidateRect (hwnd, &ptoSrc->rectClip, TRUE); 497: InvalidateRect (hwnd, &ptoDest->rectClip, TRUE); 498: } 499: CloseClipboard (); 500: } break; 501: 502: /******************************************************************\ 503: * WM_COMMAND, AID_CYCLE 504: * 505: * Post a COPY and PASTE command message to this window so that with 506: * one key stroke the user can copy the DEST image into the clipboard, 507: * paste it down into the SRC hdc and cause the blt. 508: \******************************************************************/ 509: case AID_CYCLE: 510: PostMessage (hwnd, WM_COMMAND, MAKELONG (AID_COPY , 1), 0); 511: PostMessage (hwnd, WM_COMMAND, MAKELONG (AID_PASTE, 1), 0); 512: break; 513: } /* end switch */ 514: 515: break; /* end wm_command */ 516: 517: 1.1.1.3 ! root 518: } /* end switch */ ! 519: return (DefWindowProc(hwnd, message, wParam, lParam)); 1.1 root 520: } 521: 522: 523: 524: 525: 526: 527: /**************************************************************************\ 528: * 529: * function: DlgProc() 530: * 531: * input parameters: normal window procedure parameters. 532: * 533: * This is the dialog that sits on top of the window (it is streblted on the 534: * WM_SIZE message of the main window). In this window procedure, handle 535: * the command messages that arise as the user selects buttons on this 536: * dialog. Also handle user messages for filling in entry field values. 537: * 538: * global variables: 539: * hwndMain - the main window. also the parent of this dialog 540: * ptoSrc - pointer to the source track object 541: * hdcSrc - device context for the right half the window. 542: * ptoDest - pointer to the destination track object 543: * hdcDest - device context for the left half the window. 544: * hbmSrc - bitmap handle for the source bitmap. 545: * 546: * strebltMode - Selection from combo box, to be used in SetStretchMode() 547: * iPatternBrush - Selection from combo box, set into the hdc. 548: \**************************************************************************/ 549: LONG APIENTRY DlgProc(HWND hwnd, UINT message, UINT wParam, LONG lParam) 550: { 551: char buffer[MAXCHARS]; 552: 553: UNREFERENCED_PARAMETER(lParam); 554: 555: switch (message) { 556: /**********************************************************************\ 557: * WM_INITDIALOG 558: * 559: * Fill the entry fields with sensible original values. 560: * Also fill the combo boxes with the text entries from lookup tables. 561: \**********************************************************************/ 562: case WM_INITDIALOG: { 563: int i; 564: 565: for ( i = DID_X; i<= DID_SRCHEIGHT; i++) 566: SetDlgItemText(hwnd, i , "0"); 567: 568: SetDlgItemText(hwnd, DID_ROP0 , "cc"); 569: SetDlgItemText(hwnd, DID_ROP1 , "00"); 570: SetDlgItemText(hwnd, DID_ROP2 , "20"); 571: 572: for (i = 0; i< NMODES; i++) 573: SendDlgItemMessage (hwnd, DID_CB_MODE, CB_INSERTSTRING, 574: (DWORD) -1, (LONG)strebltModes[i].String); 575: 576: for (i = 0; i< NPATTERNS; i++) 577: SendDlgItemMessage (hwnd, DID_CB_PATTERN, CB_INSERTSTRING, 578: (DWORD) -1, (LONG)Patterns[i].String); 579: 580: for (i = 0; i< NROPS; i++) 581: SendDlgItemMessage (hwnd, DID_CB_ROPS, CB_INSERTSTRING, 582: (DWORD) -1, (LONG)StandardROPs[i].String); 583: 584: 585: } return TRUE; 586: 587: 588: /**********************************************************************\ 589: * WM_PUTUPDESTRECT 590: * 591: * wParam - HDC with the needed world transform. 592: * lParam - Pointer to the track object. 593: * 594: * Fill the entry fields for the destination rectangle points. 595: * Conditionally change <x,y> or <width,height> depending on tracking mode. 596: \**********************************************************************/ 597: case WM_PUTUPDESTRECT: { 598: POINT p1,p2, origin; 599: PTrackObject pto; 600: HDC hdc; 601: 602: hdc = (HDC) wParam; 603: pto = (PTrackObject) lParam; 604: GetViewportOrgEx (hdc, &origin); 605: 606: p1.x = pto->rect.left; 607: p1.y = pto->rect.top; 608: LPtoDP (pto->hdc, &p1, 1); 609: 610: p2.x = pto->rect.right; 611: p2.y = pto->rect.bottom; 612: LPtoDP (pto->hdc, &p2, 1); 613: p2.x -= p1.x; p2.y -= p1.y; 614: 615: p1.x -= origin.x; p1.y -= origin.y; 616: 617: if (!(pto->Mode & TMSIZEXY)) { 618: SetDlgItemInt(hwnd, DID_X, p1.x, TRUE); 619: SetDlgItemInt(hwnd, DID_Y, p1.y, TRUE); 620: } 621: 622: if (!(pto->Mode & TMMOVE)) { 623: SetDlgItemInt(hwnd, DID_WIDTH, p2.x, TRUE); 624: SetDlgItemInt(hwnd, DID_HEIGHT, p2.y, TRUE); 625: } 626: } return FALSE; 627: 628: 629: 630: 631: /**********************************************************************\ 632: * WM_PUTUPSRCRECT 633: * 634: * wParam - HDC with the needed world transform. 635: * lParam - Pointer to the track object. 636: * 637: * Fill the entry fields for the source rectangle points. 638: * Conditionally change <x,y> or <width,height> depending on tracking mode. 639: \**********************************************************************/ 640: case WM_PUTUPSRCRECT: { 641: POINT p1,p2, origin; 642: PTrackObject pto; 643: HDC hdc; 644: 645: hdc = (HDC) wParam; 646: pto = (PTrackObject) lParam; 647: GetViewportOrgEx (hdc, &origin); 648: 649: p1.x = pto->rect.left; 650: p1.y = pto->rect.top; 651: LPtoDP (pto->hdc, &p1, 1); 652: 653: p2.x = pto->rect.right; 654: p2.y = pto->rect.bottom; 655: LPtoDP (pto->hdc, &p2, 1); 656: p2.x -= p1.x; p2.y -= p1.y; 657: 658: p1.x -= origin.x; p1.y -= origin.y; 659: 660: if (!(pto->Mode & TMSIZEXY)) { 661: SetDlgItemInt(hwnd, DID_XSRC, p1.x, TRUE); 662: SetDlgItemInt(hwnd, DID_YSRC, p1.y, TRUE); 663: } 664: 665: if (!(pto->Mode & TMMOVE)) { 666: SetDlgItemInt(hwnd, DID_SRCWIDTH, p2.x, TRUE); 667: SetDlgItemInt(hwnd, DID_SRCHEIGHT, p2.y, TRUE); 668: } 669: } return FALSE; 670: 671: 672: 673: 674: case WM_COMMAND: 675: 676: switch (LOWORD(wParam)) { 677: 678: /******************************************************************\ 679: * WM_COMMAND, DID_DRAW 680: * 681: * Draw button hit - send main window message to call StretchBlt(). 682: \******************************************************************/ 683: case DID_DRAW: 684: SendMessage (hwndMain, WM_STRETCHBLT, 0,0); 685: break; 686: 687: 688: /******************************************************************\ 689: * WM_COMMAND, DID_NEWSRC 690: * 691: * Try to get a new source bitmap. If successful, store it in the 692: * global handle (hbmSrc) then invalidate two sub windows so that 693: * we force a complete repaint in both. 694: \******************************************************************/ 695: case DID_NEWSRC: { 696: HBITMAP hbm; 697: if ( hbm = GetBitmap (hdcSrc, hInst, FALSE)) { 698: DeleteObject (hbmSrc); 699: hbmSrc = hbm; 700: InvalidateRect (hwndMain, &ptoSrc->rectClip, TRUE); 701: InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE); 702: } 703: 704: } break; 705: 706: 707: /******************************************************************\ 708: * WM_COMMAND, DID_CB_MODE 709: * 710: * A new streblt mode was selected. Look up the value, store it 711: * in a global variable (strebltMode), then force a new StretchBlt 712: \******************************************************************/ 713: case DID_CB_MODE: 714: if (HIWORD (wParam) == CBN_SELCHANGE) { 715: int iSel; 716: 717: iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0); 718: strebltMode = strebltModes[iSel].Value; 719: 720: SendMessage (hwndMain, WM_STRETCHBLT, 0,0); 721: } 722: break; 723: 724: 725: /******************************************************************\ 726: * WM_COMMAND, DID_CB_PATTERN 727: * 728: * A new pattern brush was selected. Look up the value, store it 729: * in a global variable (iPatternBrush), then force a new StretchBlt 730: \******************************************************************/ 731: case DID_CB_PATTERN: 732: if (HIWORD (wParam) == CBN_SELCHANGE) { 733: int iSel; 734: 735: iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0); 736: iPatternBrush = Patterns[iSel].Value; 737: 738: SendMessage (hwndMain, WM_STRETCHBLT, 0,0); 739: } 740: break; 741: 742: 743: 744: /******************************************************************\ 745: * WM_COMMAND, DID_CB_ROPS 746: * 747: * A new standard rop entry was selected. Lookup the value, 748: * then break it into three parts, convert to hex, and put 749: * it in the proper entry fields. 750: \******************************************************************/ 751: case DID_CB_ROPS: 752: if (HIWORD (wParam) == CBN_SELCHANGE) { 753: int iSel, rop; 754: 755: iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0); 756: rop = StandardROPs[iSel].Value; 757: sprintf (buffer, "%2x", (rop & 0x000000ff)); 758: SetDlgItemText(hwnd, DID_ROP2, buffer); 759: rop /= 256; 760: sprintf (buffer, "%2x", (rop & 0x000000ff)); 761: SetDlgItemText(hwnd, DID_ROP1, buffer); 762: rop /= 256; 763: sprintf (buffer, "%2x", (rop & 0x000000ff)); 764: SetDlgItemText(hwnd, DID_ROP0, buffer); 765: 766: SendMessage (hwndMain, WM_STRETCHBLT, 0,0); 767: } 768: break; 769: 770: 771: 772: 773: } /* end switch */ 774: 775: 776: return FALSE; /* end WM_COMMAND */ 777: 778: 1.1.1.3 ! root 779: } /* end switch */ ! 780: return 0; 1.1 root 781: } 782: 783: 784: #define TICKSPACE 20 785: 786: /**************************************************************************\ 787: * 788: * function: DrawGrids() 789: * 790: * input parameters: 791: * hdc - Device context to draw into. 792: * width, height - size of the rectangle to fill with grids. 793: * 794: * global variables: none. 795: * 796: \**************************************************************************/ 797: VOID DrawGrids (HDC hdc, int width, int height) 798: { 799: int i; 800: 801: /* Draw vertical lines. Double at the axis */ 802: for (i = 0; i<= width; i+=TICKSPACE){ 803: MoveToEx (hdc, i, 0, NULL); 804: LineTo (hdc, i, height); 805: } 806: MoveToEx (hdc, 1, 0, NULL); 807: LineTo (hdc, 1, height); 808: 809: /* Draw horizontal lines. Double at the axis */ 810: for (i = 0; i<= height; i+=TICKSPACE){ 811: MoveToEx (hdc, 0,i, NULL); 812: LineTo (hdc, width,i); 813: } 814: MoveToEx (hdc, 0, 1, NULL); 815: LineTo (hdc, width,1); 816: 817: return; 818: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.