Getting empty update rectangle in OnPaint after calling InvalidateRect on a layered window

Posted by Shawn on Stack Overflow See other posts from Stack Overflow or by Shawn
Published on 2010-06-04T16:47:40Z Indexed on 2010/06/09 21:42 UTC
Read the original article Hit count: 229

Filed under:
|
|

I'm trying to figure out why I've been getting an empty update rectangle when I call InvalidateRect on a transparent window. The idea is that I've drawn something on the window (it gets temporarily switched to have an alpha of 1/255 for the drawing), and then I switch it to full transparent mode (i.e. alpha of 0) in order to interact with the desktop & to be able to move the drawing around the screen on top of the desktop.

When I try to move the drawing, I get its bounding rectangle & use it to call InvalidateRect, as such:

InvalidateRect(m_hTarget, &winRect, FALSE);

I've confirmed that the winRect is indeed correct, and that m_hTarget is the correct window & that its rectangle fully encompasses winRect.

I get into the OnPaint handler in the class corresponding to m_hTarget, which is derived from a CWnd. In there, I create a CPaintDC, but when I try to access the update rectangle (dcPaint.m_ps.rcPaint) it's always empty. This rectangle gets passed to a function that determines if we need to update the screen (by using UpdateLayeredWindow in the case of a transparent window).

If I hard-code a non-empty rectangle in here, the remaining code works correctly & I am able to move the drawing around the screen.

I tried changing the 'FALSE' parameter to 'TRUE' in InvalidateRect, with no effect. I also tried using a standard CDC, and then using BeginPaint/EndPaint method in my OnPaint handler, just to ensure that CPaintDC wasn't doing something odd ... but I got the same results.

The code that I'm using was originally designed for opaque windows. If m_hTarget corresponds to an opaque window, the same set of function calls results in the correct (i.e. non-empty) rectangle being passed to OnPaint. Once the window is layered, though, it doesn't seem to work right.

© Stack Overflow or respective owner

Related posts about c++

Related posts about onpaint