它们之间的的关系如下:
CObject
public |------CDCpublic |------|------CClientDC
public |------|------CPaintDC
public |------|------CWindowDC
public |------|------CMetaFileDC
CDC
msdn上关于CDC是这样描述的
The CDC
object provides member functions for working with a device context, such as a display or printer, as well as members for working with a display context associated with the client area of a window.
(翻译:CDC对象提供用于处理设备上下文的成员函数,例如显示器或打印机,以及用于处理与窗口的客户区域相关联的显示上下文的成员。)
可以使用GetDC() 来获取设备的DC。同时,在使用完后,记得调用ReleaseDC()来释放DC
CPaintDC
It performs a CWnd::beginpaint at construction time and CWnd::EndPaint at destruction time.A CPaintDC
object can only be used when responding to a WM_PAINT message, usually in your OnPaint message-handler member function.
(翻译:它在构造时调用CWnd :: BeginPaint,在析构时CWnd :: EndPaint结束。CPaintDC对象只能在响应WM_PAINT消息时使用,通常在您的OnPaint消息处理程序成员函数中。)
来处理窗口的绘制消息
CClientDC
This means that the device context associated with a CClientDC
object is the client area of a window.
(翻译:这意味着与CClientDC
对象相关联的设备上下文是窗口的客户端区域。)
其构造函数中包含了GetDC,析构函数中包含了ReleaseDC。所以在每次显示的去调用它们。
CWindowDC
Calls the Windows function GetWindowDC()at construction time and ReleaseDC() at destruction time. This means that a CWindowDC
object accesses the entire screen area of a CWnd (both client and nonclient areas).
(翻译:在构建时调用Windows函数GetWindowDC,并在析构时调用ReleaseDC。这意味着一个CWindowDC
对象访问CWnd的整个屏幕区域(客户端和非客户端区域))
CWindowDC 和CClientDC一样。不需要显示的去调用GetDC和ReleaseDC函数。CWindowDC可以访问整个窗口区域,包括了客户区和非客户区。
其中,CPaintDC和CClientDC的坐标原点是位于客户区的左上角。而CWindowDC的坐标原点是位于屏幕的左上角。CpaintD