functions in the CDC class are used to perform bitwise
operations on pixel maps, or bitmaps.
simplest pixel operation is SetPixel, which sets a pixel,
specified by its logical coordinates, to a specific color.
The current color of a pixel can be retrieved by calling GetPixel. A somewhat faster variant of
SetPixelV; this version of the function does not return
the actual color of the pixel.
member function can be used to transfer a rectangular area
from one location to another. BitBlt can also be used to
transfer blocks of pixels between device contexts. Thus,
BitBlt is the operation of choice when, for mfc
are transferring blocks of pixels from the screen to a
compatible memory bitmap or vice versa.
A variant of
BitBlt, StretchBlt, also transfers blocks of pixels from
one location to another, but it also compresses and
stretches the pixel block to fit the destination
rectangle. The stretching mode (the method used to
eliminate and/or add pixels) is controlled by
SetStretchMode (GetStretchMode) and
member function combines the pixels on the device with the
pixels of the selected brush in a bitwise logical
operation. The Mucancode.netBlt operation combines the source and
destination bitmaps and a mucancode.net bitmap in a bitwise logical
To fill an
area in a bitmap using the current brush, call the
FloodFill or ExtFloodFill member functions.
To scroll an
area within a device context, use the ScrollDC member
function. This function also provides information about
the areas uncovered by the scrolling operation, which you
can use for repainting purposes. However, if you wish to
scroll the entire client area of a window, you should
instead utilize the CWnd::ScrollWindow function.
In order to
perform text output, applications can use any one of a
wide selection of text output and font manipulation
text output function is CDC::TextOut. This function places
a character string at a specified location using the
currently selected font. A variant, CDC::ExtTextOut,
outputs a character string into a specified rectangle.
variant is TabbedTextOut; this function expands tabs in
the text that is to be outputted in accordance with an
array specifying tab stop positions.
The color of
the text is determined by SetTextColor (use
to retrieve the current setting). The horizontal and
vertical text alignment are determined by SetTextAlign (GetTextAlign).
This function can also be used to specify that text output
functions use the current position (as specified by
functions such as MoveTo) rather than any coordinates
specified in the function call as the location of the
possible to obtain the size of a block of text without
actually drawing the text. The function
calculates the width and height of a line of text using
the attribute device context. To perform the same
calculation using the output device context, use
GetOutputTextExtent. The functions GetTabbedTextExtent
GetOutputTabbedTextExtent perform the same calculations
for text that contains tab characters that are to be
SetTextJustification can be used in conjunction with the
function GetTextExtent to create justified text.
SetTextJustification evenly distributes an amount of space
among the break characters (usually spaces) in the text. A
related function is SetTextCharacterSpacing, which can be
used to set the amount of intercharacter spacing. (Use
GetTextCharacterSpacing to retrieve the current setting.)
sophisticated text output function is DrawText. This
function can be used to output multiline
text. Note that
the DrawText function is not recorded in standard Windows
metafiles. (It is recorded in enhanced metafiles.)
GrayString function can be used to create grayed (dimmed)
about the current font can be obtained using GetTextFace
(retrieves the name of the font), GetTextMetrics
(retrieves a TEXTMETRICS structure containing information
about the font currently selected in the attribute device
context), and GetOutputTextMetrics (same, for the output
other CDC member functions deal with scaleable (TrueType)
fonts and information that can be retrieved from such font
particularly important GDI capability is the ability to
clip output to a specified rectangle or region. This
capability is used by Windows throughout; for example,
clipping is used to only repaint portions of a window that
are not covered by other windows.
can make explicit use of clipping through a series of CDC
member functions that act as wrappers for similar GDI
functions. These include SelectClipRgn, ExcludeClipRect,
ExcludeUpdateRgn, IntersectClipRect, and OffsetClipRgn. To
obtain the smallest rectangle that encloses the entire
clipping region, call GetClipBox. To determine whether a
point or any parts of a rectangle are inside the clipping
region, use the PtVisible or RectVisible member functions.
also maintain a bounding rectangle in which bounding
information about the bounds of subsequent drawing
operations is accumulated. To access the bounding
rectangle, use the SetBoundsRect and
printing is essentially no different from drawing into any
other kind of device contexts, the CDC class offers a
series of printer escape member functions that control
specific aspects of printing.
document and individual pages is controlled by the
StartDoc, StartPage, EndPage, and EndDoc member functions.
To abort the printing process (and effectively erase
everything that has been sent to the printer device
context since the last call to StartDoc), call the
AbortDoc member function. Note that if printing is
canceled or the printer device driver returns any other
error, your application should not call the EndDoc or
AbortDoc member functions.
SetAbortDoc member function to create a callback function
that Windows calls when the print job is canceled or must
be terminated. The QueryAbort member function can be used
to query this callback function to determine whether
printing should be aborted.
driver specific features can be accessed through the
Escape member function. However, because Win32 provides
many more printer control functions, the utility of this
function relative to earlier Windows implementations has
class also offers member functions that encapsulate path
functionality. A path is a complex shape create by a
series of GDI function calls. A path is created by calling
the BeginPath member function, calling the appropriate
drawing functions, and calling EndPath. Calling EndPath
automatically selects the path into the device context for
that manipulate paths include CloseFigure, FlattenPath,
StrokePath, and WidenPath. The path can be rendered into
the device context using StrokePath. To render the path's
interior, use FillPath; or you can use
to render both the path's contours and its interior at the
same time using the current pen and brush.
A path can
be turned into a clipping region by calling SelectClipPath.
UCanCode Advance E-XD++
CAD Drawing and Printing Solution
Source Code Solution for C/C++, .NET V2018 is released!
Contact UCanCode Software
To buy the source code or learn more about with: