Linguagem C - Inserir imagem BITMAP


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

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

int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPI, PSTR szCL, int iCS) {
    HWND     hwnd;
    MSG      msg;
    WNDCLASS wndclass;

    HBITMAP      imagem;
    HBRUSH       hBrush;

    imagem = LoadBitmap(hI, IMAGEM);
    hBrush  = CreatePatternBrush(imagem);
    DeleteObject(imagem);

    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;
    wndclass.lpszMenuName  = NULL;
    wndclass.lpszClassName = TEXT("Background");

    if(!RegisterClass(&wndclass)) {
        MessageBox(NULL,TEXT("Error!"),"Title",MB_ICONERROR);
        return 0;
    }

    hwnd = CreateWindow(
        TEXT("Background"), TEXT("Imagem BITMAP"), 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 lP) {
    switch(msg) {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
    }
    return DefWindowProc(hwnd, msg, wP, lP);
}





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

#define IMAGEM   12
#define IDI_ICON 13




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

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

IDI_ICON ICON              "icone.ico"
IMAGEM BITMAP  DISCARDABLE "img.bmp"

Comentários