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

发布于 2024-09-04 16:25:21 字数 830 浏览 6 评论 0原文

我试图找出为什么当我在透明窗口上调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舂唻埖巳落 2024-09-11 16:25:21

我想我已经弄清楚了 - 这是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文