BitBlt mit anschließendem Rectangle geht nicht
-
Hallo!
Ich habe ein schnuckeliges Programm, welches mir brav einen Screenshot vom Desktop anzeigt. Jetzt soll der Benutzer dort einen Rechteckigen Bereich malen, mit dem das Programm dann was weiter macht...
Ich hab erstmal leicht angefangen und wollte in meinen Screenshot einfach ein Rechteck dazumalen, ich sehs nur leider nicht

void OnPaint(HWND hwnd) { HDC hBitmapdc, hWindowdc; HBITMAP hOld; PAINTSTRUCT ps; RECT rc; // If the bitmap is present, draw it if (hDesktopBitmap_) { // Get window dc and start paint hWindowdc = BeginPaint(hwnd, &ps); hWindowdc = GetDC(hwnd); // Create compatible dc hBitmapdc = CreateCompatibleDC(hWindowdc); // Select the bitmap into the dc hOld = SelectBitmap(hBitmapdc, hDesktopBitmap_); // Get width and height of this window GetClientRect(hwnd, &rc); // Draw the bitmap to the window leaving a border of 20 pixels BitBlt(hWindowdc, 0, 0, rc.right, rc.bottom, hBitmapdc, 0, 0, SRCCOPY); // draw a rectangle RECT rectangle; HBRUSH hBrush; Rectangle(hWindowdc, 100, 100, 100, 100); hBrush = CreateSolidBrush(RGB(255,0,0)) ; FillRect (hWindowdc, &rectangle, hBrush) ; // Delete bitmap dc DeleteDC(hBitmapdc); // Tell windows that you've updated the window EndPaint(hwnd, &ps); } }Wie gesagt, der Screenshot wird angezeigt, BitBlt tut also seine Arbeit, aber das Rechteck ist nicht sichtbar.

Kann mir da einer helfen?
-
Hallo!
Hint:BOOL Rectangle(hc, Left, Top, Right, Bottom);Du rufst Rectangle mit NULL-rect auf, FillRect mit rectangle=müll.
Wozu GetDC (ohne ReleaseDC), wo ist DeleteObject(hBrush), und dazu auch SelectObject(hWindowdc, hOld) fehlt.
-
Jetzt hab ichs gecheckt. Für alle dies interessiert, hier der Code:
void OnPaint(HWND hwnd) { HDC hBitmapdc, hWindowdc; HBITMAP hOld; PAINTSTRUCT ps; RECT rc; // If the bitmap is present, draw it if (hDesktopBitmap_) { // Get window dc and start paint hWindowdc = BeginPaint(hwnd, &ps); hWindowdc = GetDC(hwnd); // Create compatible dc hBitmapdc = CreateCompatibleDC(hWindowdc); // Select the bitmap into the dc hOld = SelectBitmap(hBitmapdc, hDesktopBitmap_); SelectObject(hWindowdc, hOld); // Get width and height of this window GetClientRect(hwnd, &rc); // Draw the bitmap to the window leaving a border of 20 pixels BitBlt(hWindowdc, 0, 0, rc.right, rc.bottom, hBitmapdc, 0, 0, SRCCOPY); // draw a rectangle RECT rectangle; HBRUSH hBrush; rectangle.left = 100; rectangle.top = 100; rectangle.bottom = 300; rectangle.right = 600; hBrush = CreateSolidBrush(RGB(255,0,0)) ; FillRect (hWindowdc, &rectangle, hBrush) ; // Delete bitmap dc DeleteDC(hBitmapdc); DeleteObject(hBrush); // Tell windows that you've updated the window EndPaint(hwnd, &ps); } }Danke für den Tip!