Ellipse(hdcMMask, 0, 0, cxBitmap, cyBitmap);


/**Eu me deitei e dormi; acordei, porque o Senhor me sustentou. Salmos 3:5*/

#include <windows.h>
#include "resource.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

static TCHAR nm[] = "Ellipse(hdcMMask, 0, 0, cxBitmap, cyBitmap);";

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPI,PSTR szCL, int iCS) {
    static TCHAR szAppName[] = TEXT("BitMask");
    HWND         hwnd;
    MSG          msg;
    WNDCLASS     wndclass;
    wndclass.style         = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc   = WndProc;
    wndclass.cbClsExtra    = 0;
    wndclass.cbWndExtra    = 0;
    wndclass.hInstance     = hInstance;
    wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
    wndclass.lpszMenuName  = NULL;
    wndclass.lpszClassName = szAppName;
    if(!RegisterClass(&wndclass)) {
        MessageBox(NULL, TEXT("Error!"), szAppName, MB_ICONERROR);
        return 0;
    }
    hwnd = CreateWindow(
        szAppName, nm, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
        NULL, NULL, hInstance, NULL
    );
    ShowWindow(hwnd, iCS);
    UpdateWindow(hwnd);
    while(GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage (&msg);
        FreeConsole();
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wP, LPARAM lParam) {
    static HBITMAP   hBitmapImag, hBitmapMask;
    static HINSTANCE hInstance;
    static int       cxClient, cyClient, cxBitmap, cyBitmap;
    BITMAP           bitmap;
    HDC              hdc, hdcMemImag, hdcMMask;
    int              x, y;
    PAINTSTRUCT      ps;

    switch(msg) {
        case WM_CREATE:
            hInstance   = ((LPCREATESTRUCT) lParam)->hInstance;
            hBitmapImag = LoadBitmap(hInstance, TEXT("Matthew"));
            GetObject(hBitmapImag, sizeof(BITMAP), &bitmap);
            cxBitmap    = bitmap.bmWidth;
            cyBitmap    = bitmap.bmHeight;
            hdcMemImag  = CreateCompatibleDC(NULL);
            SelectObject(hdcMemImag, hBitmapImag);
            hBitmapMask = CreateBitmap(cxBitmap, cyBitmap,1,1,NULL);
            hdcMMask = CreateCompatibleDC(NULL);
            SelectObject(hdcMMask, hBitmapMask);
            SelectObject(hdcMMask, GetStockObject(BLACK_BRUSH));
            Rectangle(hdcMMask, 0, 0, cxBitmap, cyBitmap);
            SelectObject(hdcMMask, GetStockObject(WHITE_BRUSH));
            Ellipse(hdcMMask, 0, 0, cxBitmap, cyBitmap);
            BitBlt(hdcMemImag,0,0,cxBitmap,cyBitmap,hdcMMask,0,0,SRCAND);
            DeleteDC(hdcMemImag);
            DeleteDC(hdcMMask);
            return 0;
        case WM_SIZE:
            cxClient = LOWORD(lParam);
            cyClient = HIWORD(lParam);
            return 0;
        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            /**Select bitmaps into memory DCs*/
            hdcMemImag = CreateCompatibleDC(hdc);
            SelectObject(hdcMemImag, hBitmapImag);
            hdcMMask = CreateCompatibleDC(hdc);
            SelectObject(hdcMMask, hBitmapMask);
            // Center image
            x = (cxClient - cxBitmap) / 2;
            y = (cyClient - cyBitmap) / 2;
            // Do the bitblts
            BitBlt(hdc,x,y,cxBitmap,cyBitmap,hdcMMask,0,0,0x220326);
            BitBlt(hdc,x,y,cxBitmap,cyBitmap,hdcMemImag,0,0,SRCPAINT);
            DeleteDC(hdcMemImag);
            DeleteDC(hdcMMask);
            EndPaint(hwnd, &ps);
            return 0;
        case WM_DESTROY:
            DeleteObject(hBitmapImag);
            DeleteObject(hBitmapMask);
            PostQuitMessage(0);
            return 0;
    }
    return DefWindowProc(hwnd, msg, wP, lParam);
}

/********************Arquivo: resource.h********************/

/********************Arquivo: resource.rc********************/

#include "resource.h"
#include "afxres.h"

MATTHEW                 BITMAP  DISCARDABLE     "image.bmp"

Comentários