Zeichnen einer Bitmap im Hintergrund eines Fensters
-
Wie? Die Bitmap liegt in Form eines char Buffers vor. Wie zeichne ich sie?
HBITMAP bmp; switch(msg) { case WM_DESTROY: { PostQuitMessage(0); }break; case WM_PAINT: { PAINTSTRUCT ps; HDC MemDC; HDC hdc = BeginPaint(hWnd, &ps); bmp = (HBITMAP)BUF; // BUF = Bitmap // Create a memory device compatible with the above DC variable MemDC = CreateCompatibleDC(hdc); // Select the new bitmap SelectObject(MemDC, bmp); // Copy the bits from the memory DC into the current dc BitBlt(hdc, 0, 0, 450, 400, MemDC, 0, 0, SRCCOPY); // Restore the old bitmap DeleteDC(MemDC); DeleteObject(bmp); EndPaint(hWnd, &ps); }return 0; } return DefWindowProc(hWnd,msg,wParam,lParam); }
-
viele Wege führen nach Rom:
LRESULT WINAPI WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { RECT rect; static int x=0; switch (uMsg) { case WM_CLOSE: { PostQuitMessage(0); }break; case WM_CREATE: { SetTimer(hWnd,0,20,0); } break; case WM_TIMER: { GetClientRect(hWnd,&rect); if(x>(rect.right-20)) x=0; else x++; InvalidateRect(hWnd,0,0); } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hMemDC; HBITMAP hBmp; GetClientRect(hWnd,&rect); BeginPaint(hWnd,&ps); hMemDC=CreateCompatibleDC(ps.hdc); hBmp=(HBITMAP)SelectObject(hMemDC,CreateCompatibleBitmap(ps.hdc,rect.right,rect.bottom)); FillRect(hMemDC,&rect,(HBRUSH)GetStockObject(WHITE_BRUSH)); Rectangle(hMemDC,x,10,x+20,10+20); BitBlt(ps.hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY); DeleteObject(SelectObject(hMemDC,hBmp)); DeleteDC(hMemDC); EndPaint(hWnd,&ps); } break; default: return DefWindowProc(hWnd,uMsg,wParam,lParam); } return 0; }
-
Dann würde ich jetzt noch WM_ERASEBKGND behandeln und TRUE zurückgeben. Das verhindert unnötiges Flackern.