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