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