当WindowProc收到WM_PAINT消息时如何找到窗口的脏区域...?

发布于 2024-10-06 17:05:23 字数 699 浏览 5 评论 0原文

我有一个用 C++(非 MFC)编写的内部 API,在 win32 API 之上实现。我的应用程序正在为每个 WM_PAINT 调用绘制整个窗口。有没有一种方法可以让我只找到脏/无效区域,以便我可以优化绘制函数以仅在与脏区域相交的视图中绘制。

我在 BeginPaint - EndPaint 语句之间尝试了以下代码,但失败了。整个窗户都是黑色的。如果我将优化标志设置为 0,窗口绘制得很好,但绘制速度太慢。有什么建议吗???

#if Optimize
// get the inval region and pass it down
    HRGN invalRegion = CreateRectRgn(0,0,0,0);  
    int retVal = ::GetClipRgn( myHDC,invalRegion);  
    Assert (retVal != -1);  
    if(retVal == 0)         
       return;     // nothing to draw.  
    else if(retVal == 1)        
       Draw(invalRegion); // a valid dirty region handle.   
    else
#endif
       Draw(NULL); // this results in drawing calls to all views in the window.

I have an inhouse API written in C++ (no MFC), implemented on top of win32 API. My app is drawing the whole window for each WM_PAINT call. Is there a way i could find only the dirty/inval region so that i can optimize my draw functions to draw only in the views that intersect with the dirty region.

I tried the following code between BeginPaint - EndPaint statements and failed horribly. whole window was black. If i set Optimize flag to 0, the window draws fine but the drawing is too slow. Any suggestions...??.

#if Optimize
// get the inval region and pass it down
    HRGN invalRegion = CreateRectRgn(0,0,0,0);  
    int retVal = ::GetClipRgn( myHDC,invalRegion);  
    Assert (retVal != -1);  
    if(retVal == 0)         
       return;     // nothing to draw.  
    else if(retVal == 1)        
       Draw(invalRegion); // a valid dirty region handle.   
    else
#endif
       Draw(NULL); // this results in drawing calls to all views in the window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

演出会有结束 2024-10-13 17:05:23

您是否尝试过使用PAINTSTRUCT中的rcPaint RECT? GetClipRgn 的文档明确指出它不 指的是由 BeginPaint 创建的剪切区域,但仅限于通过 SelectClipRgn 显式选择的区域。

Have you tried using the rcPaint RECT from the PAINTSTRUCT? GetClipRgn's docs specifically say it does not refer to the clipping region created by BeginPaint, but only those explicitly selected in via SelectClipRgn.

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