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