简体   繁体   English

在窗口中绘画之前是否需要使更新区域无效

[英]Is it necessary to invalidate update region before painting in the window

Is it necessary to invalidate the update region before immediate painting (in response to a user action) if I use Direct2D? 如果我使用Direct2D,是否需要在立即绘制之前(响应用户操作)使更新区域无效? Or is calling RenderTarget::BeginDraw() enough? 还是调用RenderTarget::BeginDraw()足够了? I need to quickly repaint some part of the window outside of the WM_PAINT message. 我需要在WM_PAINT消息之外快速重绘窗口的某些部分。 If I don't invalidate the update region, sometimes the whole client area of the window becomes black, no drawings are visible. 如果我不使更新区域无效,则有时窗口的整个工作区都变成黑色,则看不到任何图形。 But if I do invalidate the update region, the system sends a WM_PAINT message before I validate the update region back, which causes unnecessary drawing operations to be performed. 但是,如果我确实使更新区域无效,则系统会在我验证更新区域之前发送WM_PAINT消息,这将导致执行不必要的绘制操作。 How should I implement the immediate drawing operations outside the WM_PAINT message handler if I use Direct2D? 如果使用Direct2D,应如何在WM_PAINT消息处理程序之外实现即时绘图操作?

Invalidating and validating are ways to get a WM_PAINT message and to handle one. 无效和验证是获取WM_PAINT消息并处理一条消息的方法。 If you're painting outside of a WM_PAINT handler, you shouldn't be invalidating or validating as part of that drawing. 如果要在WM_PAINT处理程序之外绘画,则不应作为该绘图的一部分进行无效或验证。

That said, it's very uncommon to paint outside of the WM_PAINT handler. 也就是说,在WM_PAINT处理程序之外进行绘制是非常罕见的。 It can be very hard to get it right. 正确处理可能非常困难。 My advice would be to get everything working via a traditional WM_PAINT handler first, and then decide whether it's really necessary to do some painting outside that handler. 我的建议是首先通过传统的WM_PAINT处理程序使所有工作正常,然后决定是否真的需要在该处理程序外部进行绘画。

Typically when using Direct2D in a game-like application you perform no drawing in WM_PAINT and draw using Direct2D many times per second. 通常,在类似游戏的应用程序中使用Direct2D时,您不会在WM_PAINT中执行绘制,而是每秒使用Direct2D进行多次绘制。 Another common technique, for cases where you draw something once and do not create a new drawing many times per second is storing the drawing in a back buffer of some sort; 对于您一次绘制一次且每秒不多次创建新图形的情况,另一种常见技术是将图形存储在某种形式的后缓冲区中。 that way you can 'blit' it to the screen in response to a WM_PAINT message. 这样,您可以将其“屏蔽”到屏幕以响应WM_PAINT消息。

Of course, this could be different for your case, depending on the type of program you are creating. 当然,根据您所创建的程序类型的不同,情况可能会有所不同。

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

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