Annotation of mstools/samples/plgblt/plgblt.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.