how to retain a painted region of a window when other window is moved on it
-
[^]I am writing a colour picker program using Windows API. It has an option to zoom the area around the mouse position. The program uses a short cut key. To do this i capture 200x200 around the mouse and display by stretching it in a new window using StretchBlt. Here is the code.
void showZoomDialog()
{
HWND hwndPopup = CreateWindowEx(WS_EX_TOOLWINDOW, szClassName, "Zoom", WS_POPUP | WS_BORDER | WS_CAPTION,
200, 120, 200, 200, NULL, NULL, hinst, NULL);ShowWindow(hwndPopup, SW\_SHOWNORMAL); UpdateWindow(hwndPopup); HDC popupdc = GetDC(hwndPopup); int nScreenWidth = GetSystemMetrics(SM\_CXSCREEN); int nScreenHeight = GetSystemMetrics(SM\_CYSCREEN); HDC hDesktopDC = GetDC(NULL); HDC hCaptureDC = CreateCompatibleDC(hDesktopDC); HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight); SelectObject(hCaptureDC,hCaptureBitmap); //BitBlt(popupdc, 0,0, 200, 200, hDesktopDC, mx-100, my-100, SRCCOPY|CAPTUREBLT); StretchBlt(popupdc, 0,0, 200, 200, hDesktopDC, mx-12, my-12, 24, 24, SRCCOPY|CAPTUREBLT); //this is right ReleaseDC(NULL,hDesktopDC); ReleaseDC(NULL,popupdc); DeleteDC(hCaptureDC); DeleteObject(hCaptureBitmap);
}
When i press the short cut key the new window appears with the expected output in it. When i move some other window over it then window is painted white. I searched and found that WM_PAINT message is used. I have not used it as i want to be clear of what it is for. Still understand the working of GDI+. How do i retain the painted window? I don't want other window to erase the content. [Here is the screen shot]
Today's Beautiful Moments are Tomorrow's Beautiful Memories
-
[^]I am writing a colour picker program using Windows API. It has an option to zoom the area around the mouse position. The program uses a short cut key. To do this i capture 200x200 around the mouse and display by stretching it in a new window using StretchBlt. Here is the code.
void showZoomDialog()
{
HWND hwndPopup = CreateWindowEx(WS_EX_TOOLWINDOW, szClassName, "Zoom", WS_POPUP | WS_BORDER | WS_CAPTION,
200, 120, 200, 200, NULL, NULL, hinst, NULL);ShowWindow(hwndPopup, SW\_SHOWNORMAL); UpdateWindow(hwndPopup); HDC popupdc = GetDC(hwndPopup); int nScreenWidth = GetSystemMetrics(SM\_CXSCREEN); int nScreenHeight = GetSystemMetrics(SM\_CYSCREEN); HDC hDesktopDC = GetDC(NULL); HDC hCaptureDC = CreateCompatibleDC(hDesktopDC); HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight); SelectObject(hCaptureDC,hCaptureBitmap); //BitBlt(popupdc, 0,0, 200, 200, hDesktopDC, mx-100, my-100, SRCCOPY|CAPTUREBLT); StretchBlt(popupdc, 0,0, 200, 200, hDesktopDC, mx-12, my-12, 24, 24, SRCCOPY|CAPTUREBLT); //this is right ReleaseDC(NULL,hDesktopDC); ReleaseDC(NULL,popupdc); DeleteDC(hCaptureDC); DeleteObject(hCaptureBitmap);
}
When i press the short cut key the new window appears with the expected output in it. When i move some other window over it then window is painted white. I searched and found that WM_PAINT message is used. I have not used it as i want to be clear of what it is for. Still understand the working of GDI+. How do i retain the painted window? I don't want other window to erase the content. [Here is the screen shot]
Today's Beautiful Moments are Tomorrow's Beautiful Memories
I am afraiod you are doing it the wrong way. All actions in Windows are driven by messages received in the application (or thread) message pump. When a
WM_PAINT
message is received it indicates that the Window in question requires repainting. If you do your window painting in some other function and ignore theWM_PAINT
messages then you will get the result that you see.