bitmap aus resourcen datei wird nicht angezeigt
-
/*--------------------------------------------------------- SYSMETS1.C -- Ermittlung der Maße des Systems, Version 1 (c) Charles Petzold, 1998 ---------------------------------------------------------*/ #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 ("SysMets1") ; 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, TEXT ("Metriken des Systems, V 1"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ; 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 hdc, hdcMem; PAINTSTRUCT ps; BITMAP bitmap; HBITMAP hBitmap; HINSTANCE hInstance; switch (message) { case WM_CREATE: hInstance=((LPCREATESTRUCT)lParam)->hInstance; hBitmap=LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1)); GetObject(hBitmap, sizeof(BITMAP), &bitmap); return 0 ; case WM_PAINT : hdc=BeginPaint(hwnd, &ps); hdcMem=CreateCompatibleDC(hdc); SelectObject(hdcMem, hBitmap); BitBlt(hdc, 50,50, bitmap.bmWidth, bitmap.bmHeight, hdcMem,0,0,SRCCOPY); DeleteDC(hdcMem); EndPaint(hwnd, &ps); return 0 ; case WM_DESTROY : PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }resource.h:
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by icondemo.rc
//
#define IDB_BITMAP1 101// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endificondemo.rc:
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS/////////////////////////////////////////////////////////////////////////////
// Deutsch (Deutschland) resources#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU)
#ifdef _WIN32
LANGUAGE LANG_GERMAN, SUBLANG_GERMAN
#pragma code_page(1252)
#endif //_WIN32#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//IDB_BITMAP1 BITMAP DISCARDABLE "bitmap1.bmp"
#endif // Deutsch (Deutschland) resources
/////////////////////////////////////////////////////////////////////////////#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
///////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
-
Ja, dann ersma Rückgabewerte prüfen

-
Mach bitmap und hBitmap mal static.
static BITMAP bitmap; static HBITMAP hBitmap;
-
Jippie. Danke!!
- Aber warum static?
-
fies schrieb:
Jippie. Danke!!
- Aber warum static?wenn du die WndProc verlässt zerstörst du variablen, static vars bleiben im speicher.
lebensdauer
http://tutorial.schornboeck.net/scope.htm
static
http://tutorial.schornboeck.net/static.htm
-
Habe ein weiteres Problem.
//Variablen für Bild HDC hdc, hdcMem; PAINTSTRUCT ps; static BITMAP bitmap; static HBITMAP hBitmap; HINSTANCE hInstance; //Variablen für Button static HWND hwndSmaller; switch (message) { case WM_CREATE: {//Bild vorbereiten hInstance=((LPCREATESTRUCT)lParam)->hInstance; hBitmap=LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1)); GetObject(hBitmap, sizeof(BITMAP), &bitmap); //Button vorbereiten hwndSmaller=CreateWindow(NULL,NULL, WS_CHILD|WS_VISIBLE|BS_BITMAP, 0,0,80,80, hwnd,(HMENU)300,hInstance,NULL); SendMessage(hwndSmaller,BM_SETIMAGE ,IMAGE_BITMAP, hBitmap);Ich möchte eine Bitmap als Button definieren aber irgendwie wird er nicht angezeigt.
-
Du willst als Fensterklasse bestimmt eher "BUTTON" als NULL benutzen ?
-
//Button vorbereiten hwndSmaller=CreateWindow(TEXT("BUTTON"),NULL, WS_CHILD|WS_VISIBLE|BS_BITMAP, 50,90,80,80, hwnd,(HMENU)300,hInstance,NULL); SendMessage(hwndSmaller,BM_SETIMAGE , (WPARAM) IMAGE_BITMAP, (LPARAM) hBitmap);Funxt leider immer noch nicht.
-
Hier funktionierts nicht:
//Button vorbereiten hwndSmaller=CreateWindow(TEXT("BUTTON"),NULL, WS_CHILD|WS_VISIBLE|BS_BITMAP, 50,90,80,80, hwnd,(HMENU)300,hInstance,NULL); //if(hwndSmaller!=NULL) MessageBox(0,"lol",0,0); SendMessage(hwndSmaller,BM_SETIMAGE , (WPARAM) IMAGE_BITMAP, (LPARAM) hBitmap);Hier wird der Button angezeigt:
//Button vorbereiten hwndSmaller=CreateWindow(TEXT("BUTTON"),NULL, WS_CHILD|WS_VISIBLE|BS_BITMAP, 50,90,80,80, hwnd,(HMENU)300,hInstance,NULL); if(hwndSmaller!=NULL) MessageBox(0,"lol",0,0); SendMessage(hwndSmaller,BM_SETIMAGE , (WPARAM) IMAGE_BITMAP, (LPARAM) hBitmap);...Hallo - warum?