Problem with Painting logic
-
Hi, In my application I have a window in which there are few buttons below the window and on clicking each of the buttons Activex controls from a list with certain conditions are shown in the same window above these buttons .This is done using painting logic.The Problem I am having here is there are prev screen left overs when I swiitch between button clicks. This bug appears only once when I open the window and do the button clicks.If at all I Minimize and Maximize my window atleast once this bug doesn't appear and every works fine. I face the issue only when I use DeviceindependentBitmap to Bitblt.I assume the problem is with clipregions. Please suggest me on the same. Below is the snippets of code
case WM_PAINT:{
RECT rc;
HDC hdcMem, hdcOld;
HBRUSH hbrBkGnd;
HFONT hfntOld;
PAINTSTRUCT ps;
DWORD dwConnectState;// Don't bother Processing any WM\_PAINT messages if you are in the process of // shutting down Window. if(! bViewClosing ) { // Get the window update region before calling BeginPaint. // Note: The BeginPaint function automatically validates the update region, so any call // to GetUpdateRgn made immediately after the call to BeginPaint retrieves an empty update region. if(hClipRgn == NULL) { hClipRgn = CreateRectRgn(0,0,0,0); GetUpdateRgn(hWnd, hClipRgn, FALSE); } ws = (WIN\_STRUCTPTR) GetWindowLong( hWnd, 0 ); BeginPaint(hWnd, (LPPAINTSTRUCT)&ps); // Get the size of the client rectangle. GetClientRect(hWnd, &rc); // Create a compatible DC. hdcMem = CreateCompatibleDC(ps.hdc); bool createFailed = false; // Create a DIBSection big enough for our client rectangle. long width = rc.right-rc.left; long height = rc.bottom-rc.top; //Start of CRL00107461 HWND dDeskWnd = GetDesktopWindow(); HDC hdc= GetDC(dDeskWnd); int nBitCount = GetDeviceCaps(hdc,BITSPIXEL); if (hbmDIBSection == NULL || dibSectionWidth < width || dibSectionHeight < height) { if (hbmDIBSection != NULL) DeleteObject(hbmDIBSection); BITMAPINFO bmi = {0}; bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = nBitCount;//32; // 32 bits per pixel.//CRL00107461 bmi.bmiHeader.biCompression = BI\_RGB; bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biWidth \* bmi.bmiHeader.biHeight \* 4;
// 4
-
Hi, In my application I have a window in which there are few buttons below the window and on clicking each of the buttons Activex controls from a list with certain conditions are shown in the same window above these buttons .This is done using painting logic.The Problem I am having here is there are prev screen left overs when I swiitch between button clicks. This bug appears only once when I open the window and do the button clicks.If at all I Minimize and Maximize my window atleast once this bug doesn't appear and every works fine. I face the issue only when I use DeviceindependentBitmap to Bitblt.I assume the problem is with clipregions. Please suggest me on the same. Below is the snippets of code
case WM_PAINT:{
RECT rc;
HDC hdcMem, hdcOld;
HBRUSH hbrBkGnd;
HFONT hfntOld;
PAINTSTRUCT ps;
DWORD dwConnectState;// Don't bother Processing any WM\_PAINT messages if you are in the process of // shutting down Window. if(! bViewClosing ) { // Get the window update region before calling BeginPaint. // Note: The BeginPaint function automatically validates the update region, so any call // to GetUpdateRgn made immediately after the call to BeginPaint retrieves an empty update region. if(hClipRgn == NULL) { hClipRgn = CreateRectRgn(0,0,0,0); GetUpdateRgn(hWnd, hClipRgn, FALSE); } ws = (WIN\_STRUCTPTR) GetWindowLong( hWnd, 0 ); BeginPaint(hWnd, (LPPAINTSTRUCT)&ps); // Get the size of the client rectangle. GetClientRect(hWnd, &rc); // Create a compatible DC. hdcMem = CreateCompatibleDC(ps.hdc); bool createFailed = false; // Create a DIBSection big enough for our client rectangle. long width = rc.right-rc.left; long height = rc.bottom-rc.top; //Start of CRL00107461 HWND dDeskWnd = GetDesktopWindow(); HDC hdc= GetDC(dDeskWnd); int nBitCount = GetDeviceCaps(hdc,BITSPIXEL); if (hbmDIBSection == NULL || dibSectionWidth < width || dibSectionHeight < height) { if (hbmDIBSection != NULL) DeleteObject(hbmDIBSection); BITMAPINFO bmi = {0}; bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = nBitCount;//32; // 32 bits per pixel.//CRL00107461 bmi.bmiHeader.biCompression = BI\_RGB; bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biWidth \* bmi.bmiHeader.biHeight \* 4;
// 4