Chapter 8 GDI Orientation and Transformations Visual C++ and MFC Fundamentals
LOGFONT LogFont;
font = this->GetFont();
font->GetLogFont(&LogFont);
char StrFont[40];
strcpy(StrFont, LogFont.lfFaceName);
CClientDC dc(this);
dc.TextOut(58, 120, StrFont, strlen(StrFont));
}
7.5 Pens.................................................................................................................
7.5.1 Introduction...........................................................................................
In the previous lesson, we mentioned that, in order to draw, two primary objects are
needed: a platform and a tool. So far, we were using the platform, called a device context.
We introduced the main device context class as the CDC class. To draw, we have been
using a pointer to CDC. Now, we need to realize that, declaring a CDC variable does not
just give us access to the device context, it also initializes it.
The device context is a combination of the platform on which the drawing is performed
and the necessary tools to draw on it. As such, when declaring a CDC variable, it also
creates and selects a black pen. This is why we have been able to draw lines and other
shapes so far.
7.5.2 The Fundamentals of a Pen................................................................
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.
To make it an efficient tool, a pen must produce some characteristics on the lines it is
asked to draw. These characteristics can range from the width of the line drawn to their
colors, from the pattern applied to the level of visibility of the lines. To manage these
properties, 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.
7.5.3 Creating and Selecting a Pen.............................................................
When you declare a CDC variable, it creates and selects a pen that can draw a 1-pixel
width black line. If you want a more refined pen, the MFC provides the CPen class.
Therefore, the first step in creating a pen is to declare a variable of CPen type, which can
be done using the default constructor as follows:
CPen NewPen;