views:

102

answers:

1

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.

A: 

I think I've figured it out - it's a combination of a limitation of Windows + some odd code in the internal framework I'm using. I have to ignore the empty rectangle & use the entire screen's rectangle instead - it seems to work fine.

Sorry if I wasn't clear enough with my initial question - I'll try to be more precise the next time.

Shawn