vc++中的cdc类(vc++学习笔记)

来源:互联网 发布:电脑断电数据库置疑 编辑:程序博客网 时间:2024/05/09 02:25

     在学习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 CDC object.
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 temporary CDC object is created and attached.
DeleteTempMap Called by the CWinApp idle-time handler to delete any temporary CDC object 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
Drawing-Tool Functions
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
Mapping Functions
等。。。