MFC - GDI

Windows provides a variety of drawing tools to use in device contexts. It provides pens to draw lines, brushes to fill interiors, and fonts to draw text. MFC provides graphic-object classes equivalent to the drawing tools in Windows.
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. Device contexts can be used to draw to the screen, to the printer, or to a metafile.
CDC is the most fundamental class to draw in MFC. The CDC object provides member functions to perform the basic drawing steps, as well as members for working with a display context associated with the client area of a window.
AbortDoc
Terminates the current print job, erasing everything the application has written to the device since the last call of the StartDoc member function.
AbortPath
Closes and discards any paths in the device context.
AddMetaFileComment
Copies the comment from a buffer into a specified enhanced-format metafile.
AlphaBlend
Displays bitmaps that have transparent or semitransparent pixels.
AngleArc
Draws a line segment and an arc, and moves the current position to the ending point of the arc.
Arc
Draws an elliptical arc.
ArcTo
Draws an elliptical arc. This function is similar to Arc, except that the current position is updated.
Attach
Attaches a Windows device context to this CDC object.
BeginPath
Opens a path bracket in the device context.
BitBlt
Copies a bitmap from a specified device context.
Chord
Draws a chord (a closed figure bounded by the intersection of an ellipse and a line segment).
CloseFigure
Closes an open figure in a path.
CreateCompatibleDC
Creates a memory-device context that is compatible with another device context. You can use it to prepare images in memory.
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.
DeleteDC
Deletes the Windows device context associated with this CDC object.
DeleteTempMap
Called by the CWinApp idle-time handler to delete any temporary CDC object created by FromHandle. Also detaches the device context.
Detach
Detaches the Windows device context from this CDC object.
DPtoHIMETRIC
Converts device units into HIMETRIC units.
DPtoLP
Converts device units into logical units.
Draw3dRect
Draws a three-dimensional rectangle.
DrawDragRect
Erases and redraws a rectangle as it is dragged.
DrawEdge
Draws the edges of a rectangle.
DrawEscape
Accesses drawing capabilities of a video display that are not directly available through the graphics device interface (GDI).
DrawFocusRect
Draws a rectangle in the style used to indicate focus.
DrawFrameControl
Draw a frame control.
DrawIcon
Draws an icon.
DrawState
Displays an image and applies a visual effect to indicate a state.
DrawText
Draws formatted text in the specified rectangle.
DrawTextEx
Draws formatted text in the specified rectangle using additional formats.
Ellipse
Draws an ellipse.
EndDoc
Ends a print job started by the StartDoc member function.
EndPage
Informs the device driver that a page is ending.
EndPath
Closes a path bracket and selects the path defined by the bracket into the device context.
EnumObjects
Enumerates the pens and brushes available in a device context.
Escape
Allows applications to access facilities that are not directly available from a particular device through GDI. Also allows access to Windows escape functions. Escape calls made by an application are translated and sent to the device driver.
ExcludeClipRect
Creates a new clipping region that consists of the existing clipping region minus the specified rectangle.
ExcludeUpdateRgn
Prevents drawing within invalid areas of a window by excluding an updated region in the window from a clipping region.
ExtFloodFill
Fills an area with the current brush. Provides more flexibility than the FloodFill member function.
ExtTextOut
Writes a character string within a rectangular region using the currently selected font.
FillPath
Closes any open figures in the current path and fills the path's interior by using the current brush and polygonfilling mode.
FillRect
Fills a given rectangle by using a specific brush.
FillRgn
Fills a specific region with the specified brush.
FillSolidRect
Fills a rectangle with a solid color.
FlattenPath
Transforms any curves in the path selected into the current device context, and turns each curve into a sequence of lines.
FloodFill
Fills an area with the current brush.
FrameRect
Draws a border around a rectangle.
FrameRgn
Draws a border around a specific region using a brush.
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.
GetArcDirection
Returns the current arc direction for the device context.
GetAspectRatioFilter
Retrieves the setting for the current aspect-ratio filter.
GetBkColor
Retrieves the current background color.
GetBkMode
Retrieves the background mode.
GetBoundsRect
Returns the current accumulated bounding rectangle for the specified device context.
GetBrushOrg
Retrieves the origin of the current brush.
GetCharABCWidths
Retrieves the widths, in logical units, of consecutive characters in a given range from the current font.
GetCharABCWidthsI
Retrieves the widths, in logical units, of consecutive glyph indices in a specified range from the current TrueType font.
GetCharacterPlacement
Retrieves various types of information on a character string.
GetCharWidth
Retrieves the fractional widths of consecutive characters in a given range from the current font.
GetCharWidthI
Retrieves the widths, in logical coordinates, of consecutive glyph indices in a specified range from the current font.
GetClipBox
Retrieves the dimensions of the tightest bounding rectangle around the current clipping boundary.
GetColorAdjustment
Retrieves the color adjustment values for the 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.
GetCurrentPosition
Retrieves the current position of the pen (in logical coordinates).
GetDCBrushColor
Retrieves the current brush color.
GetDCPenColor
Retrieves the current pen color.
GetDeviceCaps
Retrieves a specified kind of device-specific information about a given display device's capabilities.
GetFontData
Retrieves font metric information from a scalable font file. The information to retrieve is identified by specifying an offset into the font file and the length of the information to return.
GetFontLanguageInfo
Returns information about the currently selected font for the specified display context.
GetGlyphOutline
Retrieves the outline curve or bitmap for an outline character in the current font.
GetGraphicsMode
Retrieves the current graphics mode for the specified device context.
GetHalftoneBrush
Retrieves a halftone brush.
GetKerningPairs
Retrieves the character kerning pairs for the font that is currently selected in the specified device context.
GetLayout
Retrieves the layout of a device context (DC). The layout can be either left to right (default) or right to left (mirrored).
GetMapMode
Retrieves the current mapping mode.
GetMiterLimit
Returns the miter limit for the device context.
GetNearestColor
Retrieves the closest logical color to a specified logical color that the given device can represent.
GetOutlineTextMetrics
Retrieves font metric information for TrueType fonts.
GetOutputCharWidth
Retrieves the widths of individual characters in a consecutive group of characters from the current font using the output device context.
GetOutputTabbedTextExtent
Computes the width and height of a character string on the output device context.
GetOutputTextExtent
Computes the width and height of a line of text on the output device context using the current font to determine the dimensions.
GetOutputTextMetrics
Retrieves the metrics for the current font from the output device context.
GetPath
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.
GetPixel
Retrieves the RGB color value of the pixel at the specified point.
GetPolyFillMode
Retrieves the current polygon-filling mode.
GetROP2
Retrieves the current drawing mode.
GetSafeHdc
Returns m_hDC, the output device context.
GetStretchBltMode
Retrieves the current bitmap-stretching mode.
GetTabbedTextExtent
Computes the width and height of a character string on the attribute device context.
GetTextAlign
Retrieves the text-alignment flags.
GetTextCharacterExtra
Retrieves the current setting for the amount of intercharacter spacing.
GetTextColor
Retrieves the current text color.
GetTextExtent
Computes the width and height of a line of text on the attribute device context using the current font to determine the dimensions.
GetTextExtentExPointI
Retrieves the number of characters in a specified string that will fit within a specified space and fills an array with the text extent for each of those characters.
GetTextExtentPointI
Retrieves the width and height of the specified array of
glyph indices.
GetTextFace
Copies the typeface name of the current font into a buffer as a null-terminated string.
GetTextMetrics
Retrieves the metrics for the current font from the attribute device context.
GetViewportExt
Retrieves the x- and y-extents of the viewport.
GetViewportOrg
Retrieves the x- and y-coordinates of the viewport origin.
GetWindow
Returns the window associated with the display device context.
GetWindowExt
Retrieves the x- and y-extents of the associated window.
GetWindowOrg
Retrieves the x- and y-coordinates of the origin of the associated window.
GetWorldTransform
Retrieves the current world-space to page-space transformation.
GradientFill
Fills rectangle and triangle structures with a gradating color.
GrayString
Draws dimmed (grayed) text at the given location.
HIMETRICtoDP
Converts HIMETRIC units into device units.
HIMETRICtoLP
Converts HIMETRIC units into logical units.
IntersectClipRect
Creates a new clipping region by forming the intersection of the current region and a rectangle.
InvertRect
Inverts the contents of a rectangle.
InvertRgn
Inverts the colors in a region.
IsPrinting
Determines whether the device context is being used for printing.
LineTo
Draws a line from the current position up to, but not including, a point.
LPtoDP
Converts logical units into device units.
LPtoHIMETRIC
Converts logical units into HIMETRIC units.
MaskBlt
Combines the color data for the source and destination bitmaps using the given mask and raster operation.
ModifyWorldTransform
Changes the world transformation for a device context using the specified mode.
MoveTo
Moves the current position.
OffsetClipRgn
Moves the clipping region of the given device.
OffsetViewportOrg
Modifies the viewport origin relative to the coordinates of the current viewport origin.
OffsetWindowOrg
Modifies the window origin relative to the coordinates of the current window origin.
PaintRgn
Fills a region with the selected brush.
PatBlt
Creates a bit pattern.
Pie
Draws a pie-shaped wedge.
PlayMetaFile
Plays the contents of the specified metafile on the given device. The enhanced version of PlayMetaFile displays the picture stored in the given enhanced-format metafile. The metafile can be played any number of times.
PlgBlt
Performs a bit-block transfer of the bits of color data from the specified rectangle in the source device context to the specified parallelogram in the given device context.
PolyBezier
Draws one or more Bzier splines. The current position is neither used nor updated.
PolyBezierTo
Draws one or more Bzier splines, and moves the current position to the ending point of the last Bzier spline.
PolyDraw
Draws a set of line segments and Bzier splines. This function updates the current position.
Polygon
Draws a polygon consisting of two or more points (vertices) connected by lines.
Polyline
Draws a set of line segments connecting the specified points.
PolylineTo
Draws one or more straight lines and moves the current position to the ending point of the last line.
PolyPolygon
Creates two or more polygons that are filled using the current polygon-filling mode. The polygons may be disjoint or they may overlap.
PolyPolyline
Draws multiple series of connected line segments. The current position is neither used nor updated by this function.
PtVisible
Specifies whether the given point is within the clipping region.
RealizePalette
Maps palette entries in the current logical palette to the
system palette.
Rectangle
Draws a rectangle using the current pen and fills it using the current brush.
RectVisible
Determines whether any part of the given rectangle lies within the clipping region.
ReleaseAttribDC
Releases m_hAttribDC, the attribute device context.
ReleaseOutputDC
Releases m_hDC, the output device context.
ResetDC
Updates the m_hAttribDC device context.
RestoreDC
Restores the device context to a previous state saved with SaveDC.
RoundRect
Draws a rectangle with rounded corners using the current pen and filled using the current brush.
SaveDC
Saves the current state of the device context.
ScaleViewportExt
Modifies the viewport extent relative to the current values.
ScaleWindowExt
Modifies the window extents relative to the current values.
ScrollDC
Scrolls a rectangle of bits horizontally and vertically.
SelectClipPath
Selects the current path as a clipping region for the device context, combining the new region with any existing clipping region by using the specified mode.
SelectClipRgn
Combines the given region with the current clipping region by using the specified mode.
SelectObject
Selects a GDI drawing object such as a pen.
SelectPalette
Selects the logical palette.
SelectStockObject
Selects one of the predefined stock pens, brushes, or fonts provided by Windows.
SetAbortProc
Sets a programmer-supplied callback function that Windows calls if a print job must be aborted.
SetArcDirection
Sets the drawing direction to be used for arc and rectangle functions.
SetAttribDC
Sets m_hAttribDC, the attribute device context.
SetBkColor
Sets the current background color.
SetBkMode
Sets the background mode.
SetBoundsRect
Controls the accumulation of bounding-rectangle information for the specified device context.
SetBrushOrg
Specifies the origin for the next brush selected into a device context.
SetColorAdjustment
Sets the color adjustment values for the device context using the specified values.
SetDCBrushColor
Sets the current brush color.
SetDCPenColor
Sets the current pen color.
SetGraphicsMode
Sets the current graphics mode for the specified device context.
SetLayout
Changes the layout of a device context (DC).
SetMapMode
Sets the current mapping mode.
SetMapperFlags
Alters the algorithm that the font mapper uses when it maps logical fonts to physical fonts.
SetMiterLimit
Sets the limit for the length of miter joins for the device context.
SetOutputDC
Sets m_hDC, the output device context.
SetPixel
Sets the pixel at the specified point to the closest approximation of the specified color.
SetPixelV
Sets the pixel at the specified coordinates to the closest approximation of the specified color. SetPixelV is faster than SetPixel because it does not need to return the color value of the point actually painted.
SetPolyFillMode
Sets the polygon-filling mode.
SetROP2
Sets the current drawing mode.
SetStretchBltMode
Sets the bitmap-stretching mode.
SetTextAlign
Sets the text-alignment flags.
SetTextCharacterExtra
Sets the amount of intercharacter spacing.
SetTextColor
Sets the text color.
SetTextJustification
Adds space to the break characters in a string.
SetViewportExt
Sets the x- and y-extents of the viewport.
SetViewportOrg
Sets the viewport origin.
SetWindowExt
Sets the x- and y-extents of the associated window.
SetWindowOrg
Sets the window origin of the device context.
SetWorldTransform
Sets the current world-space to page-space transformation.
StartDoc
Informs the device driver that a new print job is starting.
StartPage
Informs the device driver that a new page is starting.
StretchBlt
Moves a bitmap from a source rectangle and device into a destination rectangle, stretching or compressing the bitmap if necessary to fit the dimensions of the destination rectangle.
StrokeAndFillPath
Closes any open figures in a path, strikes the outline of the path by using the current pen, and fills its interior by using the current brush.
StrokePath
Renders the specified path by using the current pen.
TabbedTextOut
Writes a character string at a specified location, expanding tabs to the values specified in an array of tab-stop positions.
TextOut
Writes a character string at a specified location using the currently selected font.
TransparentBlt
Transfers a bit-block of color data from the specified source device context into a destination device context, rendering a specified color transparent in the transfer.
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.
WidenPath
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.
Step 1 − Let us look into a simple example by creating a new MFC based single document project with MFCGDIDemo name.
Step 2 − Once the project is created, go the Solution Explorer and double click on the MFCGDIDemoView.cpp file under the Source Files folder.
Step 3 − Draw the line as shown below in CMFCGDIDemoView::OnDraw() method.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   pDC->MoveTo(95, 125);
   pDC->LineTo(230, 125);
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here
}
Step 4 − Run this application. You will see the following output.
Step 5 − The CDC::MoveTo() method is used to set the starting position of a line.
When using LineTo(), the program starts from the MoveTo() point to the LineTo() end.
After LineTo() when you do not call MoveTo(), and call again LineTo() with other point value, the program will draw a line from the previous LineTo() to the new LineTo() point.
Step 6 − To draw different lines, you can use this property as shown in the following code.
void CMFCGDIDemoView::OnDraw(CDC* pDC) { 
   pDC->MoveTo(95, 125);
   pDC->LineTo(230, 125);
   pDC->LineTo(230, 225);
   pDC->LineTo(95, 325);
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here 
}
Step 7 − Run this application. You will see the following output.
A polyline is a series of connected lines. The lines are stored in an array of POINT or CPoint values. To draw a polyline, you use the CDC::Polyline() method. To draw a polyline, at least two points are required. If you define more than two points, each line after the first would be drawn from the previous point to the next point until all points have been included.
Step 1 − Let us look into a simple example.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   CPoint Pt[7];
   Pt[0] = CPoint(20, 150);
   Pt[1] = CPoint(180, 150);
   Pt[2] = CPoint(180, 20);
   pDC−Polyline(Pt, 3);
   
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here
}
Step 2 − When you run this application, you will see the following output.
A rectangle is a geometric figure made of four sides that compose four right angles. Like the line, to draw a rectangle, you must define where it starts and where it ends. To draw a rectangle, you can use the CDC::Rectangle() method.
Step 1 − Let us look into a simple example.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   pDC->Rectangle(15, 15, 250, 160);
   
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here
}
Step 2 − When you run this application, you will see the following output.
A square is a geometric figure made of four sides that compose four right angles, but each side must be equal in length.
Let us look into a simple example.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   pDC->Rectangle(15, 15, 250, 250);
   
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here
}
When you run this application, you will see the following output.
A pie is a fraction of an ellipse delimited by two lines that span from the center of the ellipse to one side each. To draw a pie, you can use the CDC::Pie() method as shown below −
BOOL Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
The (x1, y1) point determines the upper-left corner of the rectangle in which the ellipse that represents the pie fits. The (x2, y2) point is the bottom-right corner of the rectangle.
The (x1, y1) point determines the upper-left corner of the rectangle in which the ellipse that represents the pie fits. The (x2, y2) point is the bottom-right corner of the rectangle.
The (x3, y3) point specifies the starting corner of the pie in a default counterclockwise direction.
The (x3, y3) point specifies the starting corner of the pie in a default counterclockwise direction.
The (x4, y4) point species the end point of the pie.
The (x4, y4) point species the end point of the pie.
Let us look into a simple example.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   pDC->Pie(40, 20, 226, 144, 155, 32, 202, 115);
   
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here
}
Step 2 − When you run this application, you will see the following output.
An arc is a portion or segment of an ellipse, meaning an arc is a non-complete ellipse. To draw an arc, you can use the CDC::Arc() method.
BOOL Arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
The CDC class is equipped with the SetArcDirection() method.
Here is the syntax −
int SetArcDirection(int nArcDirection)

AD_CLOCKWISE
The figure is drawn clockwise
AD_COUNTERCLOCKWISE
The figure is drawn counterclockwise
Step 1 − Let us look into a simple example.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   pDC->SetArcDirection(AD_COUNTERCLOCKWISE);
   pDC->Arc(20, 20, 226, 144, 202, 115, 105, 32);
   
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here
}
Step 2 − When you run this application, you will see the following output.
The arcs we have drawn so far are considered open figures because they are made of a line that has a beginning and an end (unlike a circle or a rectangle that do not). A chord is an arc whose two ends are connected by a straight line.
To draw a chord, you can use the CDC::Chord() method.
BOOL Chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
Let us look into a simple example.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   pDC->SetArcDirection(AD_CLOCKWISE);
   pDC->Chord(20, 20, 226, 144, 202, 115, 105, 32);
   
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here
}
When you run the above application, you will see the following output.
The arc direction in this example is set clockwise.
The color is one the most fundamental objects that enhances the aesthetic appearance of an object. The color is a non-spatial object that is added to an object to modify some of its visual aspects. The MFC library, combined with the Win32 API, provides various actions you can use to take advantage of the various aspects of colors.
The RGB macro behaves like a function and allows you to pass three numeric values separated by a comma. Each value must be between 0 and 255 as shown in the following code.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   COLORREF color = RGB(239, 15, 225);
}
Let us look into a simple example.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   COLORREF color = RGB(239, 15, 225);
   pDC->SetTextColor(color);
   pDC->TextOut(100, 80, L"MFC GDI Tutorial", 16);
   
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here
}
When you run this application, you will see the following output.
CFont encapsulates a Windows graphics device interface (GDI) font and provides member functions for manipulating the font. To use a CFont object, construct a CFont object and attach a Windows font to it, and then use the object's member functions to manipulate the font.
CreateFont
Initializes a CFont with the specified characteristics.
CreateFontIndirect
Initializes a CFont object with the characteristics given in a LOGFONT structure.
CreatePointFont
Initializes a CFont with the specified height, measured in tenths of a point, and typeface.
CreatePointFontIndirect
Same as CreateFontIndirect except that the font height is measured in tenths of a point rather than logical units.
FromHandle
Returns a pointer to a CFont object when given a Windows HFONT.
GetLogFont
Fills a LOGFONT with information about the logical font attached to the CFont object.
Let us look into a simple example.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   CFont font;
   font.CreatePointFont(920, L"Garamond");
   CFont *pFont = pDC->SelectObject(&font);
   COLORREF color = RGB(239, 15, 225);
   pDC->SetTextColor(color);
   pDC->TextOut(100, 80, L"MFC GDI Tutorial", 16);
   pDC->SelectObject(pFont);
   font.DeleteObject();
   
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
   return;

   // TODO: add draw code for native data here
}
When you run the above application, you will see the following output.
A pen is a tool used to draw lines and curves on a device context. In the graphics programming, a pen is also used to draw the borders of a geometric closed shape such as a rectangle or a polygon. Microsoft Windows considers two types of pens — cosmetic and geometric.
A pen is referred to as cosmetic when it can be used to draw only simple lines of a fixed width, less than or equal to 1 pixel. A pen is geometric when it can assume different widths and various ends. MFC provides a class CPen which encapsulates a Windows graphics device interface (GDI) pen.
CreatePen
Creates a logical cosmetic or geometric pen with the specified style, width, and brush attributes, and attaches it to the CPen object.
CreatePenIndirect
Creates a pen with the style, width, and color given in a LOGPEN structure, and attaches it to the CPen object.
FromHandle
Returns a pointer to a CPen object when
given a Windows HPEN.
GetExtLogPen
Gets an EXTLOGPEN underlying structure.
GetLogPen
Gets a LOGPEN underlying structure.
PS_SOLID
A continuous solid line.
PS_DASH
A continuous line with dashed interruptions.
PS_DOT
A line with a dot interruption at every other pixel.
PS_DASHDOT
A combination of alternating dashed and dotted points.
PS_DASHDOTDOT
A combination of dash and double dotted interruptions.
PS_NULL
No visible line.
PS_INSIDEFRAME
A line drawn just inside of the border of a closed shape.
Let us look into a simple example.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   CPen pen;
   pen.CreatePen(PS_DASHDOTDOT, 1, RGB(160, 75, 90));
   pDC->SelectObject(&pen);
   pDC->Rectangle(25, 35, 250, 125);
   
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here
}
When you run the above application, you will see the following output.
A brush is a drawing tool used to fill out closed shaped or the interior of lines. A brush behaves like picking up a bucket of paint and pouring it somewhere. MFC provides a class CBrush which encapsulates a Windows graphics device interface (GDI) brush.
CreateBrushIndirect
Initializes a brush with the style, color, and pattern specified in a LOGBRUSH structure.
CreateDIBPatternBrush
Initializes a brush with a pattern specified by a device-independent bitmap (DIB).
CreateHatchBrush
Initializes a brush with the specified hatched pattern and color.
CreatePatternBrush
Initializes a brush with a pattern specified by a bitmap.
CreateSolidBrush
Initializes a brush with the specified solid color.
CreateSysColorBrush
Creates a brush that is the default system color.
FromHandle
Returns a pointer to a CBrush object when given a handle to a Windows HBRUSH object.
GetLogBrush
Gets a LOGBRUSH structure.
Let us look into a simple example.
void CMFCGDIDemoView::OnDraw(CDC* pDC) {
   CBrush brush(RGB(100, 150, 200));
   CBrush *pBrush = pDC->SelectObject(&brush);
   pDC->Rectangle(25, 35, 250, 125);
   pDC->SelectObject(pBrush);
   
   CMFCGDIDemoDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);
   if (!pDoc)
      return;

   // TODO: add draw code for native data here
}
When you run this application, you will see the following output.
 Print
 Add Notes
 Bookmark this page