当WindowProc收到WM_PAINT消息时如何找到窗口的脏区域...?
我有一个用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用
PAINTSTRUCT
中的rcPaint RECT
? GetClipRgn 的文档明确指出它不 指的是由 BeginPaint 创建的剪切区域,但仅限于通过SelectClipRgn
显式选择的区域。Have you tried using the
rcPaint RECT
from thePAINTSTRUCT
? GetClipRgn's docs specifically say it does not refer to the clipping region created by BeginPaint, but only those explicitly selected in viaSelectClipRgn
.