Ressource Bitmap darstellen
-
#include <windows.h> #include "resource.h" LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("Gerätabhängige Bitmaps") ; 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 (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { // UNICODE-Compilierung ist die einzige realistische Fehlermöglichkeit MessageBox (NULL, TEXT ("Programm arbeitet mit Unicode und setzt Windows NT voraus!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, // Name der Fensterklasse szAppName, // Fenstertitel WS_OVERLAPPEDWINDOW, // Fensterstil CW_USEDEFAULT, // X-Position des Fensters CW_USEDEFAULT, // Y-Position des Fensters CW_USEDEFAULT, // Fensterbreite CW_USEDEFAULT, // Fensterhöhe NULL, // übergeordnetes Fenster NULL, // Menü hInstance, // Programm-Kopiezähler (Programm-ID) NULL) ; // zusätzliche Parameter ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc1, hdc, hdcmem; PAINTSTRUCT ps; static BITMAP bitmap; static int bw, bh; int x, y; HINSTANCE hInstance; switch (message) { case WM_CREATE: hInstance = ((LPCREATESTRUCT) lParam)->hInstance; HBITMAP hBitmap; hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1)); GetObject(hBitmap, sizeof(BITMAP), &bitmap); bw = bitmap.bmWidth; bh = bitmap.bmHeight; return 0 ; case WM_DESTROY: DeleteObject(hBitmap); PostQuitMessage (0) ; return 0 ; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); hdcmem = CreateCompatibleDC(hdc); SelectObject(hdcmem, hBitmap); BitBlt(hdc, 50, 50, bw, bh, hdcmem, 0, 0, SRCCOPY); DeleteDC(hdcmem); EndPaint(hwnd, &ps); ReleaseDC(hwnd, hdc1); return 0; } return DefWindowProc (hwnd, message, wParam, lParam) ; }Wieso funktioniert das nicht?
Ich habe die Bitmap als Ressource dazugetan.
Der Anwendungsbereich ist aber nur weiß
-
Dieser Code kann doch nicht gehen. hBitmap ist eine temporäere Variable.
Vor allem wundert mich, dass Dein Compiler nicht motzt, de in dem einen case Zweig wird die Variable definiert und in einem anderen benutzt.