您的位置:首页 > 编程语言 > C语言/C++

VC++中的CDC类

2016-01-22 15:19 417 查看
在学习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

CDCConstructs a CDCobject.
Initialization

CreateDCCreates a device context for a specific device.
CreateICCreates an information context for a specific device. This provides a fast way to get information about the device without creating a device context.
CreateCompatibleDCCreates a memory-device context that is compatible with another device context. You can use it to prepare images in memory.
DeleteDCDeletes the Windows device context associated with this CDC object.
FromHandleReturns 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.
DeleteTempMapCalled by the CWinApp idle-time handler to delete any temporary CDCobject created by FromHandle. Also detaches the device context.
AttachAttaches a Windows device context to this CDC object.
DetachDetaches the Windows device context from this CDC object.
SetAttribDCSets m_hAttribDC, the attribute device context.
SetOutputDCSets m_hDC, the output device context.
ReleaseAttribDCReleases m_hAttribDC, the attribute device context.
ReleaseOutputDCReleases m_hDC, the output device context.
GetCurrentBitmapReturns a pointer to the currently selected CBitmap object.
GetCurrentBrushReturns a pointer to the currently selected CBrush object.
GetCurrentFontReturns a pointer to the currently selected CFont object.
GetCurrentPaletteReturns a pointer to the currently selected CPalette object.
GetCurrentPenReturns a pointer to the currently selected CPen object.
GetWindowReturns the window associated with the display device context.
Device-Context Functions

GetSafeHdcReturns m_hDC, the output device context.
SaveDCSaves the current state of the device context.
RestoreDCRestores the device context to a previous state saved with SaveDC.
ResetDCUpdates the m_hAttribDC device context.
GetDeviceCapsRetrieves a specified kind of device-specific information about a given display device’s capabilities.
IsPrintingDetermines whether the device context is being used for printing.
Drawing-Tool Functions

GetBrushOrgRetrieves the origin of the current brush.
SetBrushOrgSpecifies the origin for the next brush selected into a device context.
EnumObjectsEnumerates the pens and brushes available in a device context.
Type-Safe Selection Helpers

SelectObjectSelects a GDI drawing object such as a pen.
SelectStockObjectSelects one of the predefined stock pens, brushes, or fonts provided by Windows.
Color and Color Palette Functions

GetNearestColorRetrieves the closest logical color to a specified logical color that the given device can represent.
SelectPaletteSelects the logical palette.
RealizePaletteMaps palette entries in the current logical palette to the system palette.
UpdateColorsUpdates 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.
GetHalftoneBrushRetrieves a halftone brush.
Drawing-Attribute Functions

GetBkColorRetrieves the current background color.
SetBkColorSets the current background color.
GetBkModeRetrieves the background mode.
SetBkModeSets the background mode.
GetPolyFillModeRetrieves the current polygon-filling mode.
SetPolyFillModeSets the polygon-filling mode.
GetROP2Retrieves the current drawing mode.
SetROP2Sets the current drawing mode.
GetStretchBltModeRetrieves the current bitmap-stretching mode.
SetStretchBltModeSets the bitmap-stretching mode.
GetTextColorRetrieves the current text color.
SetTextColorSets the text color.
GetColorAdjustmentRetrieves the color adjustment values for the device context.
SetColorAdjustmentSets the color adjustment values for the device context using the specified values.
Mapping Functions

GetMapModeRetrieves the current mapping mode.
SetMapModeSets the current mapping mode.
GetViewportOrgRetrieves the x- and y-coordinates of the viewport origin.
SetViewportOrgSets the viewport origin.
OffsetViewportOrgModifies the viewport origin relative to the coordinates of the current viewport origin.
GetViewportExtRetrieves the x- and y-extents of the viewport.
SetViewportExtSets the x- and y-extents of the viewport.
ScaleViewportExtModifies the viewport extent relative to the current values.
GetWindowOrgRetrieves the x- and y-coordinates of the origin of the associated window.
SetWindowOrgSets the window origin of the device context.
OffsetWindowOrgModifies the window origin relative to the coordinates of the current window origin.
GetWindowExtRetrieves the x- and y-extents of the associated window.
SetWindowExtSets the x- and y-extents of the associated window.
ScaleWindowExtModifies the window extents relative to the current values.
等。。。

http://blog.sina.com.cn/s/blog_4bc179a80100cuda.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: