简体   繁体   English

在分层窗口上调用InvalidateRect之后,在OnPaint中获取空的更新矩形

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

I'm trying to figure out why I've been getting an empty update rectangle when I call InvalidateRect on a transparent window. 我试图弄清楚为什么我在透明窗口上调用InvalidateRect时会得到一个空的更新矩形。 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 (ie 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. 我的想法是,我已经在窗口上绘制了一些东西(它暂时被切换为绘图的alpha为1/255),然后我将其切换为全透明模式(即alpha为0),以便与桌面,并能够在桌面上方的屏幕上移动图形。

When I try to move the drawing, I get its bounding rectangle & use it to call InvalidateRect, as such: 当我尝试移动图形时,得到其边界矩形并使用它来调用InvalidateRect,如下所示:

InvalidateRect(m_hTarget, &winRect, FALSE); 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. 我已经确认winRect确实是正确的,并且m_hTarget是正确的窗口,并且其矩形完全包含winRect。

I get into the OnPaint handler in the class corresponding to m_hTarget, which is derived from a CWnd. 我进入对应于m_hTarget的类中的OnPaint处理程序,该类派生自CWnd。 In there, I create a CPaintDC, but when I try to access the update rectangle (dcPaint.m_ps.rcPaint) it's always empty. 在其中,我创建了一个CPaintDC,但是当我尝试访问更新矩形(dcPaint.m_ps.rcPaint)时,它始终为空。 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). 将此矩形传递给确定我们是否需要更新屏幕的函数(在透明窗口的情况下,通过使用UpdateLayeredWindow)。

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. 我尝试将InvalidateRect中的'FALSE'参数更改为'TRUE',但没有任何效果。 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. 我还尝试使用标准CDC,然后在我的OnPaint处理程序中使用BeginPaint / EndPaint方法,只是为了确保CPaintDC不会做奇怪的事情……但我得到了相同的结果。

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 (ie non-empty) rectangle being passed to OnPaint. 如果m_hTarget对应于不透明窗口,则同一组函数调用会导致将正确的(即非空的)矩形传递给OnPaint。 Once the window is layered, though, it doesn't seem to work right. 但是,一旦将窗口分层,它似乎就无法正常工作。

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. 我想我已经弄清楚了-这是Windows的局限性+我正在使用的内部框架中有一些奇怪的代码的组合。 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. 抱歉,如果我对最初的问题不够清楚-下次我将尝试更加精确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM