在分层窗口上调用 InvalidateRect 后,在 OnPaint 中获取空的更新矩形
我试图找出为什么当我在透明窗口上调用 InvalidateRect 时得到一个空的更新矩形。我的想法是,我在窗口上画了一些东西(它被暂时切换为具有 1/255 的 alpha 绘图),然后我将其切换到完全透明模式(即 alpha 为 0)以便与桌面和能够在桌面顶部的屏幕上移动绘图。
当我尝试移动绘图时,我得到了它的边界矩形和用它来调用 InvalidateRect,如下所示:
InvalidateRect(m_hTarget, &winRect, FALSE);
我已经确认 winRect 确实是正确的,并且 m_hTarget 是正确的窗口&它的矩形完全包含 winRect。
我进入与 m_hTarget 对应的类中的 OnPaint 处理程序,该类派生自 CWnd。在那里,我创建了一个 CPaintDC,但是当我尝试访问更新矩形 (dcPaint.m_ps.rcPaint) 时,它始终为空。该矩形被传递给一个函数,该函数确定我们是否需要更新屏幕(在透明窗口的情况下使用 UpdateLayeredWindow)。
如果我在这里硬编码一个非空矩形,则其余代码可以正常工作并且可以正常工作。我可以在屏幕上移动绘图。
我尝试将 InvalidateRect 中的“FALSE”参数更改为“TRUE”,但没有效果。我还尝试使用标准 CDC,然后在 OnPaint 处理程序中使用 BeginPaint/EndPaint 方法,只是为了确保 CPaintDC 不会做一些奇怪的事情......但我得到了相同的结果。
我使用的代码最初是为不透明窗口设计的。如果 m_hTarget 对应于不透明窗口,则同一组函数调用会导致将正确的(即非空)矩形传递给 OnPaint。然而,一旦窗口分层,它似乎就不能正常工作了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我已经弄清楚了 - 这是 Windows 的限制 + 我正在使用的内部框架中的一些奇怪代码的组合。我必须忽略空矩形 &使用整个屏幕的矩形 - 它似乎工作正常。
抱歉,如果我最初的问题不够清楚——我下次会尽量说得更准确。
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.