运行时在窗口上绘图
我通常将绘图放在 WM_PAINT 中以在屏幕上绘制,但如果您需要在运行时解决这个问题,您还会使用 GDI 绘图 API 吗?
示例-
//In WndProc
case WM_PAINT:
{
hdc = GetWindowDC (hwnd) ;
//draw here using hdc
ReleaseDC (hwnd, hdc) ;
}
除了将绘图放入 WM_PAINT 中之外,您可以使用函数进行绘图,并且仍然获得 WM_PAINT 的重绘功能吗?
I usually put my drawing in WM_PAINT to draw on screen but if you need to figure out this at runtime would you still use GDI drawing APIs?
Example-
//In WndProc
case WM_PAINT:
{
hdc = GetWindowDC (hwnd) ;
//draw here using hdc
ReleaseDC (hwnd, hdc) ;
}
Instead of putting the drawing in WM_PAINT, can you draw using function and still get the functionality of WM_PAINT to redraw?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WM_PAINT 是异步的,这意味着当操作系统决定重新绘制窗口时调用它。您还可以通过在 WM_PAINT 消息处理程序外部调用 GetDC()/ReleaseDC() 来同步绘制。
http://msdn.microsoft.com/en -us/library/dd145126(v=vs.85).aspx
另外,在处理 WM_PAINT 消息时,您应该使用 BeginPaint()/EndPaint() 并返回 0。我见过一些奇怪的副作用这不会发生。
WM_PAINT is asynchronous, meaning its called when the OS decides it's time to repaint the window. You can also draw synchronously by calling GetDC()/ReleaseDC() outside of a WM_PAINT message handler.
http://msdn.microsoft.com/en-us/library/dd145126(v=vs.85).aspx
Also, when handling WM_PAINT messages, you should use BeginPaint()/EndPaint() and return 0. I've seen some strange side-effects when this does not happen.