Custom Buttons mit Bitmaps
-
Hallo an alle
Ich bin am verzweifeln ich habe mich an einem Button als Bitmap versucht aber
der Button wird einfach nur grau angezeigt ohne BitmaphVol1 = CreateWindow ("BUTTON", "1", BS_PUSHBUTTON | WS_BORDER| WS_CHILD |WS_VISIBLE|BS_BITMAP, 30,325, 30, 25, hWnd, (HMENU)ID_VOL1, hInst,NULL); SendMessage(hVol1, BM_SETIMAGE, (WPARAM)MAKEINTRESOURCE(ID_MYPIC), (LPARAM)hBitMap);
PS: Muss die Bitmap bestimmte Vorausetzungen haben?
crashjosh
-
Wie wäre es mit einem Blick in die Doku:
http://msdn.microsoft.com/en-us/library/bb761822(VS.85).aspxWas Du als wParam übergibst ist Unfug!
Parameters
- wParam
The type of image to associate with the button. This parameter can be one of the following values: - IMAGE_BITMAP
- IMAGE_ICON
- lParam
A handle (HICON or HBITMAP) to the image to associate with the button.
- wParam
-
Ok Wie kann ich meine Resource Datei mit IMAGE_BITMAP gleichen?
-
HDC hdc, hdcMem; static HBITMAP hBitMap; static BITMAP bitmap ; PAINTSTRUCT ps ; //... hButton = CreateWindow ("BUTTON", "", WS_CHILD | WS_VISIBLE|BS_PUSHBUTTON |BS_BITMAP |WS_BORDER, 32,32,32,32, hWnd, (HMENU)ID_BUTTON, hInst, NULL); SendMessage(hButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitMap); hBitMap = (HBITMAP)LoadImage(GetModuleHandle(NULL),"newicon.bmp",IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); GetObject (hBitMap, sizeof (BITMAP), &bitmap); //... case WM_PAINT: hdc = BeginPaint (hWnd, &ps) ; hdcMem = CreateCompatibleDC (hdc) ; SelectObject (hdcMem, hBitMap) ; BitBlt (hdc, 0, 0,bitmap.bmWidth,bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY) ; DeleteDC (hdcMem) ; EndPaint (hWnd, &ps) ; return 0 ;
Aber die Bitmap ist nicht als Button da!
-
Ich gebe Dir mal einen Tipp:
Lies mal ein paar Grundlagen!LoadBitmap verwenden und einfach die Bitmap in Deine Ressourcen-Datei einfügen...
-
Hab ich auch alles schon versucht : Resource und Header selbst geschrieben
hBitMap = (HBITMAP)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(ID_MYPIC,IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); GetObject (hBitMap, sizeof (BITMAP), &bitmap); //... case WM_PAINT: hdc = BeginPaint (hWnd, &ps) ; hdcMem = CreateCompatibleDC (hdc) ; SelectObject (hdcMem, hBitMap) ; BitBlt (hdc, 0, 0,bitmap.bmWidth,bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY) ; DeleteDC (hdcMem) ; EndPaint (hWnd, &ps) ; return 0 ;
Die Bitmap erscheint aber schräg über dem Button..
-
Und warum zeichnest Du die Bitmap selber?
Du hast doch gesagt der Button soll die Bitmap halten...Nochmal: Lies mal Grundlagen und lerne die Windows API verstehen...
-
So ich habs jetzte ^^
Für alle, denen das weiter hilft...hBitMap = (HBITMAP)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(ID_MYPIC),IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); hButton = CreateWindow ("BUTTON", "", WS_CHILD | WS_VISIBLE|BS_PUSHBUTTON |BS_BITMAP, 32,32,32,32, hWnd, (HMENU)ID_BUTTON, (HINSTANCE) GetWindowLong (hWnd, GWL_HINSTANCE), NULL); SendMessage(hButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitMap);