在学习VC++中,CDC类是在显示数据,或者使用图形,或者使用文本中必不可少的。Windows使用与设备无关的图形设备环境(DC :Device Context) 进行显示 。MFC基础类库定义了设备环境对象类----CDC类。
CDC与CGdiObject的关系
说道CDC类就不能不提一下GdiObject---图形对象类。 在Windows应用程序中,设备环境与图形对象共同工作,协同完成绘图显示工作。就像画家绘画一样,设备环境好比是画家的画布,图形对象好比是画家的画笔。用画笔在画布上绘画,不同的画笔将画出不同的画来。选择合适的图形对象和绘图对象,才能按照要求完成绘图任务。
有关CDC类的继承
父类:从 CObject 直接继承而来。继承了CObject类的各种特性,如动态创建等等。
子类:CClientDC-------代表操作窗口的DC ,是比较常用的一个子类
CMetaFileDC ------响应Meta File的DC ,Meta File是一些GDI消息。
CPaintDC-------响应WM_PAINT消息的DC。
CWindowDC ------代表整个屏幕的DC
CDC类的数据成员
数据成员只有两个:
HDC m_hDC : CDC对象使用的输出设备上下文
HDC m_hAttribDC : CDC对象使用的属性设备上下文
二者在CDC对象创建时指向相同的设备上下文。
MSDN Library中给出的构造函数及其成员函数如下(供学习之用):
Construction
CDC | Constructs a CDCobject. |
Initialization
CreateDC | Creates a device context for a specific device. |
CreateIC | Creates an information context for a specific device. This provides a fast way to get information about the device without creating a device context. |
CreateCompatibleDC | Creates a memory-device context that is compatible with another device context. You can use it to prepare images in memory. |
DeleteDC | Deletes the Windows device context associated with this CDC object. |
FromHandle | Returns a pointer to a CDC object when given a handle to a device context. If a CDC object is not attached to the handle, a temporaryCDC object is created and attached. |
DeleteTempMap | Called by the CWinApp idle-time handler to delete any temporary CDCobject created by FromHandle. Also detaches the device context. |
Attach | Attaches a Windows device context to this CDC object. |
Detach | Detaches the Windows device context from this CDC object. |
SetAttribDC | Sets m_hAttribDC, the attribute device context. |
SetOutputDC | Sets m_hDC, the output device context. |
ReleaseAttribDC | Releases m_hAttribDC, the attribute device context. |
ReleaseOutputDC | Releases m_hDC, the output device context. |
GetCurrentBitmap | Returns a pointer to the currently selected CBitmap object. |
GetCurrentBrush | Returns a pointer to the currently selected CBrush object. |
GetCurrentFont | Returns a pointer to the currently selected CFont object. |
GetCurrentPalette | Returns a pointer to the currently selected CPalette object. |
GetCurrentPen | Returns a pointer to the currently selected CPen object. |
GetWindow | Returns the window associated with the display device context. |
Device-Context Functions
GetSafeHdc | Returns m_hDC, the output device context. |
SaveDC | Saves the current state of the device context. |
RestoreDC | Restores the device context to a previous state saved with SaveDC. |
ResetDC | Updates the m_hAttribDC device context. |
GetDeviceCaps | Retrieves a specified kind of device-specific information about a given display device’s capabilities. |
IsPrinting | Determines whether the device context is being used for printing. |
Drawing-Tool Functions
GetBrushOrg | Retrieves the origin of the current brush. |
SetBrushOrg | Specifies the origin for the next brush selected into a device context. |
EnumObjects | Enumerates the pens and brushes available in a device context. |
Type-Safe Selection Helpers
SelectObject | Selects a GDI drawing object such as a pen. |
SelectStockObject | Selects one of the predefined stock pens, brushes, or fonts provided by Windows. |
Color and Color Palette Functions
GetNearestColor | Retrieves the closest logical color to a specified logical color that the given device can represent. |
SelectPalette | Selects the logical palette. |
RealizePalette | Maps palette entries in the current logical palette to the system palette. |
UpdateColors | Updates the client area of the device context by matching the current colors in the client area to the system palette on a pixel-by-pixel basis. |
GetHalftoneBrush | Retrieves a halftone brush. |
Drawing-Attribute Functions
GetBkColor | Retrieves the current background color. |
SetBkColor | Sets the current background color. |
GetBkMode | Retrieves the background mode. |
SetBkMode | Sets the background mode. |
GetPolyFillMode | Retrieves the current polygon-filling mode. |
SetPolyFillMode | Sets the polygon-filling mode. |
GetROP2 | Retrieves the current drawing mode. |
SetROP2 | Sets the current drawing mode. |
GetStretchBltMode | Retrieves the current bitmap-stretching mode. |
SetStretchBltMode | Sets the bitmap-stretching mode. |
GetTextColor | Retrieves the current text color. |
SetTextColor | Sets the text color. |
GetColorAdjustment | Retrieves the color adjustment values for the device context. |
SetColorAdjustment | Sets the color adjustment values for the device context using the specified values. |
Mapping Functions
GetMapMode | Retrieves the current mapping mode. |
SetMapMode | Sets the current mapping mode. |
GetViewportOrg | Retrieves the x- and y-coordinates of the viewport origin. |
SetViewportOrg | Sets the viewport origin. |
OffsetViewportOrg | Modifies the viewport origin relative to the coordinates of the current viewport origin. |
GetViewportExt | Retrieves the x- and y-extents of the viewport. |
SetViewportExt | Sets the x- and y-extents of the viewport. |
ScaleViewportExt | Modifies the viewport extent relative to the current values. |
GetWindowOrg | Retrieves the x- and y-coordinates of the origin of the associated window. |
SetWindowOrg | Sets the window origin of the device context. |
OffsetWindowOrg | Modifies the window origin relative to the coordinates of the current window origin. |
GetWindowExt | Retrieves the x- and y-extents of the associated window. |
SetWindowExt | Sets the x- and y-extents of the associated window. |
ScaleWindowExt | Modifies the window extents relative to the current values. |
等。。。
http://blog.sina.com.cn/s/blog_4bc179a80100cuda.html