CDC

Win32++

CDC Class

Description

A device context is a Windows data structure containing information about the drawing attributes of a device such as a display or a printer. All drawing calls are made through a device-context object, which encapsulates the Windows APIs for drawing lines, shapes, and text. Device contexts allow device-independent drawing in Windows.

The CDC class provides a GDI device context, along with a set of member functions to perform the various tasks with the device context. Member functions can also be used to create the various GDI objects, such as brushes and pens. Alternatively, GDI objects can be attached to the device context using SelectObject.

CDC Members

Initialisation and Assignment
CDC
CDC();
CDC(HDC hDC, HWND hWnd = 0);
Constructor for CDC. Attach
void Attach(HDC hDC);
Attach an existing device context to the CDC object. Detach
HDC Detach();
Detach a device context from the CDC object. The device context will be destroyed when the CDC is destroyed, unless it is detached. FromHandle
static CDC* FromHandle(HDC hDC);
Returns the CDC associated with the specified device context handle. If a CDC object doesn't already exist, a temporary CDC object is created. This temporary CDC will be deleted sometime after the processing of the current message is complete. GetHDC
HDC GetHDC() const;
Returns the Device Context handle associated with this CDC object. RestoreDC
BOOL RestoreDC(int nSavedDC) const;
Restores the DC to the specified state. The state includes selected objects and mapping modes. SaveDC
int SaveDC() const;
Saves the state of the device context. operator HDC ()
operator HDC() const;
Allow a CDC object to be used as a handle to a device context (HDC). operator HDC =
void operator = (const HDC hDC);
Used to assign a HDC to a CDC when it is created. Create and Select Bitmaps CreateBitmap
void CreateBitmap(int cx, int cy, UINT Planes, UINT BitsPerPixel, LPCVOID pvColors);
Creates a bitmap with the specified width, height, and color format (color planes and bits-per-pixel). CreateBitmapIndirect
void CreateBitmapIndirect(LPBITMAP pBitmap);
Creates a bitmap with the specified width, height, and color format (color planes and bits-per-pixel), specified in the BITMAP struct. CreateCompatibleBitmap
void CreateCompatibleBitmap(CDC* pDC, int cx, int cy);
Creates a bitmap compatible with the device that is associated with the specified device context. CreateDIBSection
void CreateDIBSection(CDC* pDC, const BITMAPINFO& bmi, UINT iUsage,
                 LPVOID *ppvBits, HANDLE hSection, DWORD dwOffset);
Creates a DIB that applications can write to directly. The function gives you a pointer to the location of the bitmap bit values. You can supply a handle to a file-mapping object that the function will use to create the bitmap, or you can let the system allocate the memory for the bitmap. CreateDIBitmap
void CreateDIBitmap(CDC* pDC, const BITMAPINFOHEADER& bmih,
           DWORD fdwInit, LPCVOID lpbInit, BITMAPINFO& bmi, UINT fuUsage);
Creates a compatible bitmap (DDB) from a DIB and, optionally, sets the bitmap bits. CreateMappedBitmap
void CreateMappedBitmap(UINT nIDBitmap, UINT nFlags /*= 0*/, 
                       LPCOLORMAP lpColorMap /*= NULL*/, int nMapSize /*= 0*/);
Creates a bitmap for use in a toolbar. DetachBitmap
CBitmap DetachBitmap();
Provides a convenient method of detaching a bitmap from a memory device context. GetBitmapData
BITMAP GetBitmapData() const;
Retrieves the current bitmap information. GetCurrentBitmap
CBitmap* GetCurrentBitmap() const;
Retrieves a pointer to the currently selected bitmap. LoadBitmap
BOOL LoadBitmap(UINT nID);
BOOL LoadBitmap(LPCTSTR lpszName);
Loads the specified bitmap resource from a module's executable file. LoadImage
BOOL LoadImage(UINT nID, int cxDesired, int cyDesired, UINT fuLoad);
BOOL LoadImage(LPCTSTR lpszName, int cxDesired, int cyDesired, UINT fuLoad);
Loads the specified bitmap resource from a module's executable file. LoadOEMBitmap
BOOL LoadOEMBitmap(UINT nIDBitmap);
Loads a predefined bitmap used by Windows. SelectObject
CBitmap* SelectObject(const CBitmap* pBitmap);
Attach an existing bitmap to the CDC. Create and Select Brushes CreateBrushIndirect
void CreateBrushIndirect(LPLOGBRUSH pLogBrush);
Creates a logical brush that has the specified style, color, and pattern. CreateDIBPatternBrush
void CreatePatternBrush(HBITMAP hbmp);
Creates a logical brush that has the pattern specified by the specified device-independent bitmap (DIB). CreateDIBPatternBrushPt
void CreateDIBPatternBrushPt(LPCVOID lpPackedDIB, UINT iUsage);
Creates a logical brush that has the pattern specified by the device-independent bitmap (DIB). CreateHatchBrush
void CreateHatchBrush(int fnStyle, COLORREF rgb);
Creates a logical brush that has the specified hatch pattern and color. CreatePatternBrush
void CreatePatternBrush(CBitmap* pBitmap);
Creates a logical brush with the specified bitmap pattern. CreateSolidBrush
void CreateSolidBrush(COLORREF rbg);
Creates a logical brush that has the specified solid color. GetCurrentBrush
CBrush* GetCurrentBrush() const;
Retrieves a pointer to the currently selected brush. GetLogBrush
LOGBRUSH GetLogBrush() const;
Retrieves the current brush information. SelectObject
CBrush* SelectObject(const CBrush* pBrush);
Attach an existing brush to the CDC. Create and Select Fonts CreateFont
void CreateFont(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight,
          DWORD fdwItalic, DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fdwCharSet,
          DWORD fdwOutputPrecision, DWORD fdwClipPrecision, DWORD fdwQuality,
          DWORD fdwPitchAndFamily, LPCTSTR lpszFace);
Creates a logical font with the specified characteristics. CreateFontIndirect
void CreateFontIndirect(LPLOGFONT plf);
Creates a logical font that has the specified characteristics. GetCurrentFont
CFont* GetCurrentFont() const;
Retrieves a pointer to the currently selected font. GetLogFont
LOGFONT GetLogFont() const;
Retrieves the current font information. SelectObject
CFont* SelectObject(const CFont* pFont);
Attach an existing font to the CDC. Create and Select Palettes CreateHalftonePalette
void CreateHalftonePalette();
Creates and selects a half tone palette into the CDC. CreatePalette
void CreatePalette(LPLOGPALETTE pLogPalette);
Creates and selects a paletted into the CDC. SelectPalette
CPalette* SelectPalette(const CPalette* pPalette, BOOL bForceBkgnd);
Attach an existing palette to the CDC. Create and Select Pens CreatePen
void CreatePen(int nStyle, int nWidth, COLORREF rgb);
Creates a logical pen that has the specified style, width, and color. CreatePenIndirect
void CreatePenIndirect(LPLOGPEN pLogPen);
Creates a logical pen that has the style, width, and color specified in a structure. GetCurrentPen
CPen* GetCurrentPen() const;
Retrieves a pointer to the currently selected pen. GetLogPen
LOGPEN GetLogPen();
Retrieves the current pen information. SelectObject
CPen* SelectObject(const CPen* pPen);
Attach an existing pen to the CDC. Retrieve and Select Stock Objects GetStockObject
HGDIOBJ GetStockObject(int nIndex) const;
Retrieves a stock brush, pen, or font into the device context.
Possible nIndex values: BLACK_BRUSH, DKGRAY_BRUSH, DC_BRUSH, HOLLOW_BRUSH, LTGRAY_BRUSH, NULL_BRUSH, WHITE_BRUSH, BLACK_PEN, DC_PEN, ANSI_FIXED_FONT, ANSI_VAR_FONT, DEVICE_DEFAULT_FONT, DEFAULT_GUI_FONT, OEM_FIXED_FONT, SYSTEM_FONT, or SYSTEM_FIXED_FONT.
SelectStockObject
HGDIOBJ SelectStockObject(int nIndex);
Selects a stock brush, pen, or font into the device context.
Possible nIndex values: BLACK_BRUSH, DKGRAY_BRUSH, DC_BRUSH, HOLLOW_BRUSH, LTGRAY_BRUSH, NULL_BRUSH, WHITE_BRUSH, BLACK_PEN, DC_PEN, ANSI_FIXED_FONT, ANSI_VAR_FONT, DEVICE_DEFAULT_FONT, DEFAULT_GUI_FONT, OEM_FIXED_FONT, SYSTEM_FONT, or SYSTEM_FIXED_FONT.
Create Regions CreateEllipticRgn
int CreateEllipticRgn(int left, int top, int right, int bottom);
Creates an elliptical region from the specified rectangle co-ordinates. CreateEllipticRgnIndirect
int CreateEllipticRgnIndirect(const RECT& rc);
Creates an elliptical region from the specified RECT. CreatePolygonRgn
int CreatePolygonRgn(LPPOINT ppt, int cPoints, int fnPolyFillMode);
Creates a polygonal region from an array of points. CreatePolyPolygonRgn
int CreatePolyPolygonRgn(LPPOINT ppt, LPINT pPolyCounts, 
                         int nCount, int fnPolyFillMode);
Creates the polygon region from a series of polygons.The polygons can overlap. CreateRectRgn
int CreateRectRgn(int left, int top, int right, int bottom);
Creates a rectangular region from the specified rectangle co-ordinates. CreateRectRgnIndirect
int CreateRectRgnIndirect(const RECT& rc);
Creates a rectangular region from a specified RECT.

Wrappers for Window API functions

Initialization

CreateCompatibleDC
BOOL CreateCompatibleDC(CDC* pDC);
Creates a memory device context (DC) compatible with the specified device.
CreateDC
BOOL CreateDC(LPCTSTR lpszDriver, LPCTSTR lpszDevice, 
        LPCTSTR lpszOutput, const DEVMODE* pInitData);
Creates a device context (DC) for a device using the specified name.
CreateIC
BOOL CreateIC(LPCTSTR lpszDriver, LPCTSTR lpszDevice,
         LPCTSTR lpszOutput, const DEVMODE* pInitData);
Creates an information context for the specified device. The information context provides a fast way to get information about the device without creating a device context (DC).
EnumObjects
int EnumObjects(int nObjectType, GOBJENUMPROC lpObjectFunc, LPARAM lParam) const;
Enumerates the pens or brushes available for the device context. This function calls the application-defined callback function once for each available object, supplying data describing that object.
GetDeviceCaps
int GetDeviceCaps(int nIndex) const;
Retrieves device-specific information for the specified device.
 
Point and Line Drawing Functions
AngleArc
BOOL AngleArc(int x, int y, int nRadius, float fStartAngle,
              float fSweepAngle) const;
Draws a line segment and an arc. The line segment is drawn from the current position to the beginning of the arc. The arc is drawn along the perimeter of a circle with the given radius and center. The length of the arc is defined by the given start and sweep angles.
Arc
BOOL Arc(int x1, int y1, int x2, int y2, int x3, 
         int y3, int x4, int y4) const;
BOOL Arc(RECT& rc, POINT ptStart, POINT ptEnd) const;
Draws an elliptical arc.
ArcTo
BOOL ArcTo(int x1, int y1, int x2, int y2, 
        int x3, int y3, int x4, int y4) const;
BOOL ArcTo(RECT& rc, POINT ptStart, POINT ptEnd) const;
Draws an elliptical arc.
CloseFigure
BOOL CloseFigure() const;
Closes the figure by drawing a line from the current position to the first point of the figure.
GetArcDirection
int GetArcDirection() const;
Retrieves the current arc direction for the specified device context. Arc and rectangle functions use the arc direction.
GetCurrentPositition
CPoint GetCurrentPosition() const;
Returns the current drawing position.
GetMiterLimit
BOOL GetMiterLimit(PFLOAT peLimit) const;
Retrieves the miter limit for the device context. The miter limit is used when drawing geometric lines that have miter joins.
GetPixel
COLORREF GetPixel(int x, int y) const;
COLORREF GetPixel(POINT pt) const;
Retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.
GetROP2
int GetROP2() const;
Retrieves the foreground mix mode of the specified device context. The mix mode specifies how the pen or interior color and the color already on the screen are combined to yield a new color.
LineTo
BOOL LineTo(int x, int y) const;
BOOL LineTo(POINT pt) const;
Draws a line from the current position up to, but not including, the specified point.
MoveTo
CPoint MoveTo(int x, int y) const;
CPoint MoveTo(POINT pt) const;
Updates the current position to the specified point.
PolyBezier
BOOL PolyBezier(const POINT* lpPoints, int nCount) const;
Draws one or more Bezier curves.
PolyBezierTo
BOOL PolyBezierTo(const POINT* lpPoints, int nCount) const;
Draws one or more Bezier curves.
PolyDraw
BOOL PolyDraw(const POINT* lpPoints, const BYTE* lpTypes, int nCount) const;
Draws a set of line segments and Bezier curves.
Polyline
BOOL Polyline(LPPOINT lpPoints, int nCount) const;
Draws a series of line segments by connecting the points in the specified array.
PolylineTo
BOOL PolylineTo(const POINT* lpPoints, int nCount) const;
Draws one or more straight lines.
PolyPolyline
BOOL PolyPolyline(const POINT* lpPoints, const DWORD* lpPolyPoints,
                 int nCount) const;
Draws multiple series of connected line segments.
SetArcDirection
int SetArcDirection(int nArcDirection) const;
Sets the drawing direction to be used for arc and rectangle functions.
SetMiterLimit
BOOL SetMiterLimit(FLOAT eNewLimit, PFLOAT peOldLimit) const;
Sets the miter limit for the device context. The miter limit is used when drawing geometric lines that have miter joins.
SetPixel
COLORREF SetPixel(int x, int y, COLORREF crColor) const;
COLORREF SetPixel(POINT pt, COLORREF crColor) const;
Sets the pixel at the specified coordinates to the specified color.
SetPixelV
BOOL SetPixelV(int x, int y, COLORREF crColor) const;
BOOL SetPixelV(POINT pt, COLORREF crColor) const;
Sets the pixel at the specified coordinates to the closest approximation of the specified color.
SetROP2
int SetROP2(int iDrawMode) const;
Sets the current foreground mix mode. GDI uses the foreground mix mode to combine pens and interiors of filled objects with the colors already on the screen.
 
Shape Drawing Functions
Chord
BOOL Chord(int x1, int y1, int x2, int y2,
           int x3, int y3, int x4, int y4) const;
BOOL Chord(const RECT& rc, POINT ptStart, POINT ptEnd) const;
Draws a chord (a region bounded by the intersection of an ellipse and a line segment, called a secant). The chord is outlined by using the current pen and filled by using the current brush..
DrawFocusRect
void DrawFocusRect(const RECT& rc) const;
Draws a rectangle in the style used to indicate that the rectangle has the focus.
Ellipse
BOOL Ellipse( int x1, int y1, int x2, int y2 ) const;
BOOL Ellipse(const RECT& rc) const;
Draws an ellipse. The center of the ellipse is the center of the specified bounding rectangle. The ellipse is outlined by using the current pen and is filled by using the current brush.
Pie
BOOL Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) const;
BOOL Pie(const RECT& rc, POINT ptStart, POINT ptEnd) const;
Draws a pie-shaped wedge bounded by the intersection of an ellipse and two radials. The pie is outlined by using the current pen and filled by using the current brush.
Polygon
BOOL Polygon(LPPOINT lpPoints, int nCount) const;
Draws a polygon consisting of two or more vertices connected by straight lines. The polygon is outlined by using the current pen and filled by using the current brush and polygon fill mode.
PolyPolygon
BOOL PolyPolygon(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount) const;
Draws a series of closed polygons. Each polygon is outlined by using the current pen and filled by using the current brush and polygon fill mode. The polygons drawn by this function can overlap.
Rectangle
BOOL Rectangle(int x1, int y1, int x2, int y2) const;
BOOL Rectangle( const RECT& rc ) const;
Draws a rectangle. The rectangle is outlined by using the current pen and filled by using the current brush.
RoundRect
BOOL RoundRect(int x1, int y1, int x2, int y2, int nWidth, int nHeight) const;
BOOL RoundRect(const RECT& rc, int nWidth, int nHeight) const;
Draws a rectangle with rounded corners. The rectangle is outlined by using the current pen and filled by using the current brush.
 
Fill and Image Drawing functions
DrawEdge
BOOL DrawEdge(const RECT& rc, UINT nEdge, UINT nFlags) const;
Draws one or more edges of the specified rectangle.
DrawFrameControl
BOOL DrawFrameControl(const RECT& rc, UINT nType, UINT nState) const;
Draws a frame control of the specified type and style.
DrawIcon
BOOL DrawIcon(int x, int y, HICON hIcon) const;
BOOL DrawIcon(POINT point, HICON hIcon) const;
Draws an icon or cursor into the specified device context.
DrawIconEx
BOOL DrawIconEx(int xLeft, int yTop, HICON hIcon, int cxWidth, int cyWidth, 
             INT istepIfAniCur, CBrush* pFlickerFreeDraw, UINT diFlags) const;
Draws an icon or cursor into the specified device context, performing the specified raster operations, and stretching or compressing the icon or cursor as specified.
FillRect
BOOL FillRect(const RECT& rc, CBrush* pBrushr) const;
Fills a rectangle by using the specified brush. This function includes the left and top borders, but excludes the right and bottom borders of the rectangle.
FillRgn
BOOL FillRgn(CRgn* pRgn, CBrush* pBrush) const;
Fills a region by using the specified brush.
FrameRect
BOOL FrameRect(const RECT& rc, CBrush* pBrush) const;
Draws a border around the specified rectangle by using the specified brush. The width and height of the border are always one logical unit.
FrameRgn
BOOL FrameRgn(CRgn* pRgn, CBrush* pBrush, int nWidth, int nHeight) const;
Draws a border around the specified region by using the specified brush.
GetPolyFillMode
int GetPolyFillMode() const;
Retrieves the current polygon fill mode.
GradientFill
void GradientFill(COLORREF Color1, COLORREF Color2, const RECT& rc, BOOL bVertical) const;
Fills the specified rectangle with a color gradient.
InvertRect
BOOL InvertRect(const RECT& rc) const;
Inverts a rectangle in a window by performing a logical NOT operation on the color values for each pixel in the rectangle's interior.
PaintRgn
BOOL PaintRgn(CRgn* pRgn) const;
Paints the specified region by using the brush currently selected into the device context.
SetPolyFillMode
int SetPolyFillMode(int iPolyFillMode) const;
Sets the polygon fill mode for functions that fill polygons.
SolidFill
void SolidFill(COLORREF Color, const RECT& rc) const;
Fills a rectangle with a solid color.
 
Bitmap Functions
BitBlt
BOOL BitBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, 
                                     int xSrc, int ySrc, DWORD dwRop) const;
Performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context.
DrawBitmap
void DrawBitmap(int x, int y, int cx, int cy, HBITMAP hbmImage, COLORREF clrMask) const;
Draws the specified bitmap to the specified DC using the mask colour provided as the transparent colour. Suitable for use with a Window DC or a memory DC.
ExtFloodFill
BOOL ExtFloodFill(int x, int y, COLORREF crColor, UINT nFillType) const;
Fills an area of the display surface with the current brush.
FloodFill
BOOL FloodFill(int x, int y, COLORREF crColor) const;
Fills an area of the display surface with the current brush. The area is assumed to be bounded as specified by the crFill parameter.
GetDIBits
int GetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, 
              LPVOID lpvBits, LPBITMAPINFO lpbi, UINT uUsage) const;
Retrieves the bits of the specified compatible bitmap and copies them into a buffer as a DIB using the specified format.
GetStretchBltMode
int GetStretchBltMode() const;
Retrieves the current stretching mode. The stretching mode defines how color data is added to or removed from bitmaps that are stretched or compressed when the StretchBlt function is called.
MaskBlt
BOOL MaskBlt(int nXDest, int nYDest, int nWidth, int nHeight, CDC* pSrc, 
              int nXSrc, int nYSrc, CBitmap* pMask, int xMask, int yMask,
              DWORD dwRop) const;
Combines the color data for the source and destination bitmaps using the specified mask and raster operation.
 Parameters:
 nXDest    x-coord of destination upper-left corner
 nYDest   y-coord of destination upper-left corner
 nWidth    width of source and destination
 nHeight   height of source and destination
 pSrc       pointer to source DC
 nXSrc     x-coord of upper-left corner of source
 nYSrc    y-coord of upper-left corner of source
 pMask   pointer to monochrome bit mask
 xMask   horizontal offset into mask bitmap
 yMask   vertical offset into mask bitmap
 dwRop   raster operation code
PatBlt
BOOL PatBlt(int x, int y, int nWidth, int nHeight, DWORD dwRop) const;
Paints the specified rectangle using the brush that is currently selected into the device context. The brush color and the surface color or colors are combined by using the specified raster operation.
SetDIBits
int SetDIBits(CBitmap* pBitmap, UINT uStartScan, UINT cScanLines, 
              CONST VOID *lpvBits, LPBITMAPINFO lpbi, UINT fuColorUse) const;
Sets the pixels in a compatible bitmap (DDB) using the color data found in the specified DIB .
SetStretchBltMode
int SetStretchBltMode(int iStretchMode) const;
Sets the bitmap stretching mode in the device context.
StretchBlt
BOOL StretchBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc,
                int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop) const;
Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
 Parameters:
 x                x-coord of destination upper-left corner
 y                y-coord of destination upper-left corner
 nWidth       width of destination rectangle
 nHeight       height of destination rectangle
 pSrcDC       handle to source DC
 xSrc           x-coord of source upper-left corner
 ySrc           y-coord of source upper-left corner
 nSrcWidth   width of source rectangle
 nSrcHeight  height of source rectangle
 dwRop        raster operation code
StretchDIBits
int StretchDIBits(int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, 
                  int YSrc, int nSrcWidth, int nSrcHeight, CONST VOID *lpBits, 
                  BITMAPINFO& bi, UINT iUsage, DWORD dwRop) const;
Copies the color data for a rectangle of pixels in a DIB to the specified destination rectangle. If the destination rectangle is larger than the source rectangle, this function stretches the rows and columns of color data to fit the destination rectangle. If the destination rectangle is smaller than the source rectangle, this function compresses the rows and columns by using the specified raster operation.
TransparentBlt
BOOL TransparentBlt(int x, int y, int nWidth, int hHeight, CDC* pSrcDC,
                     int xSrc, int ySrc, int nWidthSrc, int nHeightSrc,
                     UINT crTransparent) const;
Performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
 Parameters:
 x                    x-coord of destination upper-left corner
 y                    y-coord of destination upper-left corner
 nWidth           width of destination rectangle
 hHeight          height of destination rectangle
 pSrcDC          pointer to source DC
 xSrc               x-coord of source upper-left corner
 ySrc               y-coord of source upper-left corner
 nWidthSrc       width of source rectangle
 nHeightSrc      height of source rectangle
 crTransparent  color to make transparent
 
Palette and color Functions
GetColorAdjustment
BOOL GetColorAdjustment(LPCOLORADJUSTMENT pCA) const;
Retrieves the color adjustment values for the device context.
GetCurrentPalette
CPalette* GetCurrentPalette() const;
Retrieves a pointer to the currently selected palette
GetNearestColor
COLORREF GetNearestColor(COLORREF crColor) const;
Retrieves a color value identifying a color from the system palette that will be displayed when the specified color value is used.
RealizePalette
void RealizePalette() const;
Use this to realize changes to the device context palette.
SetColorAdjustment
BOOL SetColorAdjustment(CONST COLORADJUSTMENT* pCA) const;
Sets the color adjustment values for the device context.
UpdateColors
BOOL UpdateColors() const;
Updates the client area of the specified device context by remapping the current colors in the client area to the currently realized logical palette.
 
Clipping and Region Functions
BeginPath
BOOL BeginPath() const;
Opens a path bracket in the device context.
EndPath
BOOL EndPath() const;
Combines the specified region with the current clipping region using the specified mode.
ExcludeClipRect
int ExcludeClipRect(int Left, int Top, int Right, int BottomRect) const;
int ExcludeClipRect(const RECT& rc) const;
Creates a new clipping region that consists of the existing clipping region minus the specified rectangle.
ExtSelectClipRgn
int ExtSelectClipRgn(CRgn* pRgn, int fnMode) const;
Combines the specified region with the current clipping region using the specified mode.
FlattenPath
BOOL FlattenPath() const;
Transforms any curves in the path that is selected into the device context, turning each curve into a sequence of lines.
GetClipBox
int GetClipBox(RECT& rc) const;
Retrieves the dimensions of the tightest bounding rectangle that can be drawn around the current visible area on the device. The visible area is defined by the current clipping region or clip path, as well as any overlapping windows.
GetClipPath
int GetPath(POINT* pPoints, BYTE* pTypes, int nCount) const;
Retrieves the coordinates defining the endpoints of lines and the control points of curves found in the path that is selected into the device context.
pPoints: An array of POINT structures that receives the line endpoints and curve control points, in logical coordinates.
pTypes: Pointer to an array of bytes that receives the vertex types (PT_MOVETO, PT_LINETO or PT_BEZIERTO).
nCount: The total number of POINT structures that can be stored in the array pointed to by pPoints.
GetClipRgn
int GetClipRgn(HRGN hrgn) const;
Retrieves a handle identifying the current application-defined clipping region for the specified device context.
IntersectClipRect
int IntersectClipRect(int Left, int Top, int Right, int Bottom) const;
int IntersectClipRect(const RECT& rc) const;
Creates a new clipping region from the intersection of the current clipping region and the specified rectangle.
OffsetClipRgn
int OffsetClipRgn(int nXOffset, int nYOffset) const;
Moves the clipping region of the device context by the specified offsets.
PtVisible
BOOL PtVisible(int X, int Y) const;
Determines whether the specified point is within the clipping region of a device context.
RectVisible
BOOL RectVisible(const RECT& rc) const;
Determines whether any part of the specified rectangle lies within the clipping region of a device context.
SelectClipPath
BOOL SelectClipPath(int nMode) const;
Selects the current path as a clipping region for the device context, combining the new region with any existing clipping region using the specified mode.
SelectClipRgn
int SelectClipRgn(CRgn* pRgn) const;
Selects a region as the current clipping region for the device context.
WidenPath
BOOL WidenPath() const;
Redefines the current path as the area that would be painted if the path were stroked using the pen currently selected into the device context.
 
Co-ordinate Functions
DPtoLP
BOOL DPtoLP(LPPOINT lpPoints, int nCount) const;
BOOL DPtoLP(LPRECT lpRect) const;
Converts device coordinates into logical coordinates. The conversion depends on the mapping mode of the device context, the settings of the origins and extents for the window and viewport, and the world transformation.
LPtoDP
BOOL LPtoDP(LPPOINT lpPoints, int nCount) const;
BOOL LPtoDP(LPRECT lpRect) const;
Converts logical coordinates into device coordinates. The conversion depends on the mapping mode of the device context, the settings of the origins and extents for the window and viewport, and the world transformation.
 
Layout Functions
GetLayout
DWORD GetLayout() const;
Returns the layout of a device context (DC). Can be used to retrieve the LAYOUT_RTL (for Win2000 and above).
SetLayout
DWORD SetLayout(DWORD dwLayout) const;
Changes the layout of a device context (DC).  Can be used to set the LAYOUT_RTL style (for Win2000 and above).
 
Mapping Functions
GetMapMode
int GetMapMode() const;
Retrieves the current mapping mode.
GetViewportExtEx
BOOL GetViewportExtEx(LPSIZE lpSize) const;
Retrieves the x-extent and y-extent of the current viewport for the specified device context.
GetViewportOrgEx
BOOL GetViewportOrgEx(LPPOINT lpPoint) const;
Retrieves the x-coordinates and y-coordinates of the window origin for the specified device context.
GetWindowExtEx
BOOL GetWindowExtEx(LPSIZE lpSize) const;
Retrieves the x-extent and y-extent of the window for the specified device context.
GetWindowOrgEx
BOOL GetWindowOrgEx(LPPOINT lpPoint) const;
Retrieves the x-coordinates and y-coordinates of the window origin for the specified device context.
OffsetViewportOrgEx
BOOL OffsetViewportOrgEx(int nWidth, int nHeight, LPPOINT lpPoint) const;
Modifies the viewport origin for a device context using the specified horizontal and vertical offsets.
OffsetWindowOrg
BOOL OffsetWindowOrg(int nWidth, int nHeight, LPPOINT lpPoint) const;
Modifies the viewport for a device context using the ratios formed by the specified multiplicands and divisors.
OffsetWindowOrgEx
BOOL OffsetWindowOrgEx(int nWidth, int nHeight, LPPOINT lpPoint) const;
Modifies the window origin for a device context using the specified horizontal and vertical offsets.
ScaleViewportExtEx
BOOL ScaleViewportExtEx(int xNum, int xDenom, int yNum, 
                        int yDenom, LPSIZE lpSize) const;
Modifies the viewport for a device context using the ratios formed by the specified multiplicands and divisors.
ScaleWindowExtEx
BOOL ScaleWindowExtEx(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize) const;
Modifies the window for a device context using the ratios formed by the specified multiplicands and divisors.
SetMapMode
int SetMapMode(int nMapMode) const;
Sets the mapping mode of the specified device context. The mapping mode defines the unit of measure used to transform page-space units into device-space units, and also defines the orientation of the device's x and y axes.
SetViewportExtEx
BOOL SetViewportExtEx(int x, int y, LPSIZE lpSize) const;
BOOL SetViewportExtEx(SIZE size, LPSIZE lpSizeRet) const;
Sets the horizontal and vertical extents of the viewport for a device context by using the specified values.
SetViewportOrgEx
BOOL SetViewportOrgEx(int x, int y, LPPOINT lpPoint) const;
BOOL SetViewportOrgEx(POINT point, LPPOINT lpPointRet) const;
Specifies which window point maps to the viewport origin (0,0).
SetWindowExtEx
BOOL SetWindowExtEx(int x, int y, LPSIZE lpSize) const;
BOOL SetWindowExtEx(SIZE size, LPSIZE lpSizeRet) const;
Sets the horizontal and vertical extents of the window for a device context by using the specified values.
SetWindowOrgEx
BOOL SetWindowOrgEx(int x, int y, LPPOINT lpPoint) const;
BOOL SetWindowOrgEx(POINT point, LPPOINT lpPointRet) const;
Specifies which window point maps to the viewport origin (0,0).
 
Printer Functions
AbortDoc
int AbortDoc() const;
Stops the current print job and erases everything drawn since the last call to the StartDoc function.
EndDoc
int EndDoc() const;
Ends a print job.
EndPage
int EndPage() const;
Notifies the device that the application has finished writing to a page. This function is typically used to direct the device driver to advance to a new page.
SetAbortProc
int SetAbortProc( BOOL (CALLBACK* lpfn)(HDC, int) ) const;
Sets the application-defined abort function that allows a print job to be cancelled during spooling.
StartDoc
int StartDoc(LPDOCINFO lpDocInfo) const;
Starts a print job.
StartPage
int StartPage() const;
Prepares the printer driver to accept data.
 
Font and Text Functions
DrawText
int DrawText(LPCTSTR lpszString, int nCount, const RECT& rc, UINT nFormat) const;
Draws formatted text in the specified rectangle. It formats the text according to the specified method (expanding tabs, justifying characters, breaking lines, and so forth).
DrawTextEx
int DrawTextEx(LPTSTR lpszString, int nCount, const RECT& rc, UINT nFormat, 
               LPDRAWTEXTPARAMS lpDTParams) const;
Draws formatted text in the specified rectangle.
ExtTextOut
BOOL ExtTextOut(int x, int y, UINT nOptions, const RECT& rc, LPCTSTR lpszString, 
                UINT nCount, LPINT lpDxWidths) const;
Draws text using the currently selected font, background color, and text color. You can optionally provide dimensions to be used for clipping, opaquing, or both.
GetBkColor
COLORREF GetBkColor() const;
Returns the current background color for the specified device context.
GetBkMode
int GetBkMode() const;
Returns the current background mix mode for a specified device context. The background mix mode of a device context affects text, hatched brushes, and pen styles that are not solid lines.
GetCharABCWidths
BOOL GetCharABCWidths(UINT uFirstChar, UINT uLastChar, LPABC pABC) const;
Retrieves the widths, in logical units, of consecutive characters in a specified range from the current TrueType font. This function succeeds only with TrueType fonts.
GetCharABCWidthsI
BOOL GetCharABCWidthsI(UINT giFirst, UINT cgi, LPWORD pgi, LPABC pABC) const;
Retrieves the widths, in logical units, of consecutive glyph indices in a specified range from the current TrueType font. This function succeeds only with TrueType fonts.
GetCharacterPlacement
DWORD GetCharacterPlacement(LPCTSTR pString, int nCount, int nMaxExtent, 
                            LPGCP_RESULTS pResults, DWORD dwFlags) const;
Retrieves information about a character string, such as character widths, caret positioning, ordering within the string, and glyph rendering
GetCharWidth
BOOL GetCharWidth(UINT iFirstChar, UINT iLastChar, float* pBuffer) const;
Retrieves the fractional widths of consecutive characters in a specified range from the current font.
GetCharWidthI
BOOL GetCharWidthI(UINT giFirst, UINT cgi, LPWORD pgi, int* pBuffer) const;
Retrieves the widths, in logical coordinates, of consecutive glyph indices in a specified range from the current font.
GetFontData
DWORD GetFontData(DWORD dwTable, DWORD dwOffset, LPVOID pvBuffer, DWORD cbData) const;
Retrieves font metric data for a TrueType font.
GetFontLanguageInfo
DWORD GetFontLanguageInfo() const;
Returns information about the currently selected font for the display context.
GetGlyphOutline
DWORD GetGlyphOutline(UINT uChar, UINT uFormat, LPGLYPHMETRICS pgm, DWORD cbBuffer, 
                       LPVOID pvBuffer, CONST MAT2 *lpmat2) const; 
Retrieves the outline or bitmap for a character in the TrueType font that is selected into the device context.
GetKerningPairs
DWORD GetKerningPairs(DWORD nNumPairs, LPKERNINGPAIR pkrnpair) const;
Retrieves the widths, in logical coordinates, of consecutive glyph indices in a specified range from the current font.
GetTabbedTextExtent
CSize GetTabbedTextExtent(LPCTSTR lpszString, int nCount, int nTabPositions, 
                          LPINT lpnTabStopPositions) const;
Computes the width and height of a character string. If the string contains one or more tab characters, the width of the string is based upon the specified tab stops. The GetTabbedTextExtent function uses the currently selected font to compute the dimensions of the string.
GetTextAlign
UINT GetTextAlign() const;
Retrieves the text-alignment setting for the specified device context.
GetTextCharacterExtra
int GetTextCharacterExtra() const;
Retrieves the current intercharacter spacing for the specified device context.
GetTextColor
COLORREF GetTextColor() const;
Retrieves the current text color for the specified device context.
GetTextExtentPoint32
CSize GetTextExtentPoint32(LPCTSTR lpszString, int nCount) const;
Computes the width and height of the specified string of text.
GetTextFace
int GetTextFace(int nCount, LPTSTR lpszFacename) const;
Retrieves the typeface name of the font that is selected into the specified device context.
GetTextMetrics
BOOL GetTextMetrics(TEXTMETRIC& Metrics) const;
Fills the specified buffer with the metrics for the currently selected font.
GrayString
BOOL GrayString(HBRUSH hBrush, GRAYSTRINGPROC lpOutputFunc, LPARAM lpData, 
                int nCount, int x, int y, int nWidth, int nHeight) const;
Draws gray text at the specified location. The function draws the text by copying it into a memory bitmap, graying the bitmap, and then copying the bitmap to the screen. The function grays the text regardless of the selected brush and background. GrayString uses the currently selected font.
SetBkColor
COLORREF SetBkColor(COLORREF crColor) const;
Sets the current background color to the specified color value, or to the nearest physical if the device cannot represent the specified color value.
SetBkMode
int SetBkMode(int iBkMode) const;
Sets the background mix mode of the specified device context. The background mix mode is used with text, hatched brushes, and pen styles that are not solid lines.
SetMapperFlags
DWORD SetMapperFlags(DWORD dwFlag) const;
Alters the algorithm the font mapper uses when it maps logical fonts to physical fonts.
SetTextAlign
UINT SetTextAlign(UINT nFlags) const;
Sets the text-alignment flags for the specified device context.
SetTextCharacterExtra
int SetTextCharacterExtra(int nCharExtra) const;
Sets the inter-character spacing. Inter-character spacing is added to each character, including break characters, when the system writes a line of text.
SetTextColor
COLORREF SetTextColor(COLORREF crColor) const;
Sets the text color for the specified device context to the specified color.
SetTextJustification
int SetTextJustification(int nBreakExtra, int nBreakCount) const;
Specifies the amount of space the system should add to the break characters in a string of text. The space is added when an application calls the TextOut or ExtTextOut functions.
TabbedTextOut
CSize TabbedTextOut(int x, int y, LPCTSTR lpszString, int nCount, int nTabPositions, 
                    LPINT lpnTabStopPositions, int nTabOrigin) const;
Writes a character string at a specified location, expanding tabs to the values specified in an array of tab-stop positions. Text is written in the currently selected font, background color, and text color.
TextOut
BOOL TextOut(int x, int y, LPCTSTR lpszString, int nCount) const;
Writes a character string at the specified location, using the currently selected font, background color, and text color.

Remarks

CDC objects can be used anywhere a a handle to a device context (a HDC) might be used.  They can be substituted for the HDC in any of the Windows API functions which use a HDC as a function argument.  The benefit of using a CDC object is that it automatically deletes the device context when it is destroyed, along with any GDI objects created by the CDC.

There are a number of classes inherited from CDC, namely CClientDC, CMemDC, CMetaFileDC, CPaintDC, and CWindowDC. Typically one of these more specialized classes would be used to create the device context. 

Refer to the Graphics Device Interface section of Using Win32++ for additional information on using this class.

Summary Information

Header file gdi.h
Win32/64 support Yes
WinCE support Yes