GetObject(hBitmapImag, sizeof(BITMAP), &bitmap);


/** Daniel 11 */

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

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

static TCHAR nm[] = "hBmpEntr";

int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI,PSTR szCL, int iCS) {
    static TCHAR szAppName[] = TEXT("hBmpEntr");
    HWND         hwnd;
    MSG          msg;
    WNDCLASS     wndclass;
    wndclass.style         = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc   = WndProc;
    wndclass.cbClsExtra    = 0;
    wndclass.cbWndExtra    = 0;
    wndclass.hInstance     = hI;
    wndclass.hIcon         = LoadIcon(hI, IDI_ICON);
    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, hI, 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, hBmpEntr;
    static HINSTANCE hInstance;
    static int       cxClient, cyClient, cxBitmap, cyBitmap;
    BITMAP           bitmap;
    HDC              hdc, hdcMemImag, entr;
    int              x, y;
    PAINTSTRUCT      ps;

    switch(msg) {
        case WM_CREATE:
            hInstance   = ((LPCREATESTRUCT) lParam)->hInstance;
            hBitmapImag = LoadBitmap(hInstance, TEXT("Apocalipse"));
            GetObject(hBitmapImag, sizeof(BITMAP), &bitmap);
            cxBitmap    = bitmap.bmWidth;
            cyBitmap    = bitmap.bmHeight;
            hdcMemImag  = CreateCompatibleDC(NULL);
            SelectObject(hdcMemImag, hBitmapImag);
            hBmpEntr = CreateBitmap(cxBitmap, cyBitmap,1,1,NULL);
            entr = CreateCompatibleDC(NULL);

            SelectObject(entr, hBmpEntr);

            SelectObject(entr, GetStockObject(BLACK_BRUSH));

            Rectangle(entr, 0, 0, cxBitmap, cyBitmap);
            SelectObject(entr, GetStockObject(WHITE_BRUSH));
            Ellipse(entr, 0, 0, cxBitmap, cyBitmap);
            BitBlt(hdcMemImag,0,0,cxBitmap,cyBitmap,entr,0,0,SRCAND);
            DeleteDC(hdcMemImag);
            DeleteDC(entr);
            return 0;
        case WM_SIZE:
            cxClient = LOWORD(lParam);
            cyClient = HIWORD(lParam);
            return 0;
        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            hdcMemImag = CreateCompatibleDC(hdc);
            SelectObject(hdcMemImag, hBitmapImag);
            entr = CreateCompatibleDC(hdc);
            SelectObject(entr, hBmpEntr);

            x = (cxClient - cxBitmap) / 2;
            y = (cyClient - cyBitmap) / 2;

            BitBlt(hdc,x,y,cxBitmap,cyBitmap,entr,0,0,0x220326);
            BitBlt(hdc,x,y,cxBitmap,cyBitmap,hdcMemImag,0,0,SRCPAINT);
            DeleteDC(hdcMemImag);
            DeleteDC(entr);
            EndPaint(hwnd, &ps);
            return 0;
        case WM_DESTROY:
            DeleteObject(hBitmapImag);
            DeleteObject(hBmpEntr);
            PostQuitMessage(0);
            return 0;
    }
    return DefWindowProc(hwnd, msg, wP, lParam);
}



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

#define IDI_ICON 1





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

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

Apocalipse     BITMAP  DISCARDABLE  "img6.bmp"
IDI_ICON       ICON                 "icone.ico"

Comentários