Runtime Drawing on window
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) ;
开发者_如何学Go
}
Instead of putting the drawing in WM_PAINT, can you draw using function and still get the functionality of WM_PAINT to redraw?
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.
精彩评论