Bitmap-Ressource wird erst nach resize vom Fenster angezeigt
-
case WM_PAINT: hdc = BeginPaint (hwnd, &ps); // Load the bitmap from the resource bmpExercising = LoadBitmap(hIn, MAKEINTRESOURCE(IDB_BITMAP1)); // Create a memory device compatible with the above DC variable MemDCExercising = CreateCompatibleDC(hdc); // Select the new bitmap SelectObject(MemDCExercising, bmpExercising); // Copy the bits from the memory DC into the current dc BitBlt(hdc, 0, 0, 450, 400, MemDCExercising, 0, 0, SRCCOPY); // Restore the old bitmap DeleteDC(MemDCExercising); DeleteObject(bmpExercising); EndPaint (hwnd, &ps);
-
Das ist WinAPI und hat hier gar nichts zu suchen.
-
Stimmt, bitte um Verschiebung...
-
Kann mir keiner helfen?
-
Wenn du UpdateWindow aufrufst, sollte das schon gehen.
Zeig sonst mal den kompletten Code. (Bitte auf das nötigste reduziert!)
-
drakon schrieb:
Wenn du UpdateWindow aufrufst, sollte das schon gehen.
Zeig sonst mal den kompletten Code. (Bitte auf das nötigste reduziert!)
case WM_PAINT: hdc = BeginPaint (hwnd, &ps); // Load the bitmap from the resource bmpExercising = LoadBitmap(hIn, MAKEINTRESOURCE(IDB_BITMAP1)); // Create a memory device compatible with the above DC variable MemDCExercising = CreateCompatibleDC(hdc); // Select the new bitmap SelectObject(MemDCExercising, bmpExercising); // Copy the bits from the memory DC into the current dc BitBlt(hdc, 0, 0, 450, 400, MemDCExercising, 0, 0, SRCCOPY); UpdateWindow(hwnd); // <<<<<<<<<<<<<<<< FUNKTIONIERT NICHT DeleteDC(MemDCExercising); DeleteObject(bmpExercising); EndPaint (hwnd, &ps);
-
Eine lauffähige Anwendung. Ich weiss ja nicht, was du sonst so machst..
-
drakon schrieb:
Eine lauffähige Anwendung. Ich weiss ja nicht, was du sonst so machst..
Ironie? Also komplett kopieren? 300 Zeilen?
#ifndef IDC_STATIC #define IDC_STATIC (-1) #endif #define IDB_BITMAP1 100DAS IST DIE HEADER DATEI
// Generated by ResEdit 1.5.2 // Copyright (C) 2006-2010 // http://www.resedit.net #include <windows.h> #include <commctrl.h> #include <richedit.h> #include "resource.h" // // Bitmap resources // LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDB_BITMAP1 BITMAP "C:\\Users\\MUSTER\\Desktop\\bitmap_0110.bmp"Und das die Ressourcendatei.
-
Reduziert!
Das erstellen eines Fensters und da reinzeichnen ist keine 300 Zeilen..
-
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc, MemDCExercising; PAINTSTRUCT ps; HWND hwndButton1, hwndButton2, hwndButton3; HFONT hFont = CreateFont(0,0,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH,TEXT("Calibri")); HBITMAP bmpExercising; switch (message) { case WM_PAINT: hdc = BeginPaint (hwnd, &ps); // Load the bitmap from the resource bmpExercising = LoadBitmap(hIn, MAKEINTRESOURCE(IDB_BITMAP1)); // Create a memory device compatible with the above DC variable MemDCExercising = CreateCompatibleDC(hdc); // Select the new bitmap SelectObject(MemDCExercising, bmpExercising); // Copy the bits from the memory DC into the current dc BitBlt(hdc, 0, 0, 450, 400, MemDCExercising, 0, 0, SRCCOPY); // Restore the old bitmap DeleteDC(MemDCExercising); DeleteObject(bmpExercising); EndPaint (hwnd, &ps); return 0; case WM_CREATE : hwndButton1 = CreateWindow ( "button", "Senden", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 280, 230, 100, 50, hwnd, (HMENU)1, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL); SendMessage(hwndButton1, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); hwndButton2 = CreateWindow ( "button", "Verbinden", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WM_SETFONT, 280, 20, 100, 25, hwnd, (HMENU)4, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL); SendMessage(hwndButton2, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); hwndButton3 = CreateWindow ( "button", "Trennen", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 280, 55, 100, 25, hwnd, (HMENU)5, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL); SendMessage(hwndButton3, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); hwndEdit2 = CreateWindow ( "edit", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | WS_BORDER | ES_AUTOVSCROLL, 20, 230, 250, 50, hwnd, (HMENU)2, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL); SendMessage(hwndEdit2, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); hwndEdit3 = CreateWindow ( "edit", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | WS_BORDER | ES_AUTOVSCROLL, 20, 20, 250, 200, hwnd, (HMENU)3, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL); SendMessage(hwndEdit3, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));Das ist es.
Und hier Teile meiner WinMain()
int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow) { ip = szCmdLine; char szName[] = "Fensterklasse"; HBRUSH MyBrush = CreateSolidBrush( RGB( 255,105,180 ) ); WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hI; wc.hIcon = LoadIcon (NULL, IDI_WINLOGO); wc.hCursor = 0; wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = szName; RegisterClass (&wc); hwnd = CreateWindow (szName, "Chat-Client", WS_OVERLAPPEDWINDOW, 0, 0, 420, 350, NULL, NULL, hI, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); //----------------------------------------------------------------------------------- LONG_PTR pOldWndProc = SetWindowLongPtr(hwndEdit2,GWL_WNDPROC, LONG_PTR(SpecialWndProc)); SetWindowLongPtr(hwndEdit2,GWL_USERDATA,pOldWndProc); MSG msg; hIn = hI; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; }
-
Was ist daran so schwer zu verstehen:
Ein komplettes auf das nötigste reduzierte Beispiel, wo du das gleiche Verhalten hast.Ich habe weder Lust zuerst eine ganze Applikation daraus zu bauen, noch das unwichtige wieder rauszuwerfen. Das ist schon deine Aufgabe!
Oftmals findet man so die Fehler selbst, weil man den bei der Reduktion oft Dinge findet, die eben doch einen Einfluss haben können auf Dinge, die man gar nicht erwartet.Es ist also auch vor allem als Selbsthilfe gedacht, dass ich so etwas schreibe.. Und wenn es nicht klappt, dann hast du wenigstens ein kompaktes, kleines Beispiel, wo wir Fehler schneller finden können.
-
#include "resource.h" #include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); HWND hwndEdit3, hwndEdit2, hwnd; HINSTANCE hIn; int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow) { char szName[] = "Fensterklasse"; HBRUSH MyBrush = CreateSolidBrush( RGB( 255,105,180 ) ); WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hI; wc.hIcon = LoadIcon (NULL, IDI_WINLOGO); wc.hCursor = 0; wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = szName; RegisterClass (&wc); hwnd = CreateWindow (szName, "Chat-Client", WS_OVERLAPPEDWINDOW, 0, 0, 420, 350, NULL, NULL, hI, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); //----------------------------------------------------------------------------------- MSG msg; hIn = hI; 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, MemDCExercising; PAINTSTRUCT ps; HWND hwndButton1, hwndButton2, hwndButton3; HBITMAP bmpExercising; HFONT hFont = CreateFont(0,0,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH,TEXT("Calibri")); switch (message) { case WM_PAINT: hdc = BeginPaint (hwnd, &ps); // Load the bitmap from the resource bmpExercising = LoadBitmap(hIn, MAKEINTRESOURCE(IDB_BITMAP1)); // Create a memory device compatible with the above DC variable MemDCExercising = CreateCompatibleDC(hdc); // Select the new bitmap SelectObject(MemDCExercising, bmpExercising); // Copy the bits from the memory DC into the current dc BitBlt(hdc, 0, 0, 450, 400, MemDCExercising, 0, 0, SRCCOPY); // Restore the old bitmap DeleteDC(MemDCExercising); DeleteObject(bmpExercising); EndPaint (hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); }Dazugehörige Headerdatei:
#ifndef IDC_STATIC #define IDC_STATIC (-1) #endif #define IDB_BITMAP1 100
-
Da ist immernoch sehr viel drin, was wahrscheinlich nichts mit dem Problem zu tun hat. (Die ganzen Buttons und Texfelder interessieren ja nicht).
Das so viel Zeugs ein Problem ist zeigt sich daher da, dass ich keine Ahung habe, was nicht gut ist. Bei mir wird die Message korrekt nach dem starten gesendet. (ich habe einfach einen Breakpoints dort gesetzt und er hat sofort dort gehalten).
Das Fenster wird gezeichnet und alles hat anscheinend den korrekten Platz.
-
drakon schrieb:
Da ist immernoch sehr viel drin, was wahrscheinlich nichts mit dem Problem zu tun hat. (Die ganzen Buttons und Texfelder interessieren ja nicht).
Das so viel Zeugs ein Problem ist zeigt sich daher da, dass ich keine Ahung habe, was nicht gut ist. Bei mir wird die Message korrekt nach dem starten gesendet. (ich habe einfach einen Breakpoints dort gesetzt und er hat sofort dort gehalten).
Das Fenster wird gezeichnet und alles hat anscheinend den korrekten Platz.
Hab alles entfernt, mehr geht nicht. Ich kann ja noch die Ressourcendatei hochladen. Das Fenster ist bei mir am Anfang WEIß -> sprich das Bild wird erst nach resize angezeigt!
Hier nochmal die Resource:
// Generated by ResEdit 1.5.2 // Copyright (C) 2006-2010 // http://www.resedit.net #include <windows.h> #include <commctrl.h> #include <richedit.h> #include "resource.h" // // Bitmap resources // LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDB_BITMAP1 BITMAP "C:\\Users\\MUSTER\\Desktop\\bitmap_0110.bmp"
-
Ja. Die Ressource wäre nicht schlecht.
Aber bist du sicher, dass der Code nicht ausgeführt wird? - Bei mir kommt die Message korrekt an.
-
Ja, ich quäle mich seit Stunden damit... Das Bild erscheint ja! Aber leider nicht sofort nach Start des Programmes!
-
Keine Idee?