A pen is a graphics tools that a Windows application uses to draw lines and curves. Drawing applications use pens to draw freehand lines, straight lines, and curves. CAD applications use pens to draw visible lines, hidden lines, section lines, center lines and so on. Word-processing and desktop publishing applications use pens to draw borders and rules. And, spreadsheet applications use pens to designate trends in graphs and to outline bar- and pie-charts.
There are two types of pens: cosmetic and geometric. The dimensions of a cosmetic pen are specified in device units. The dimensions of a geometric pen are specified in world units. This means that lines drawn with a cosmetic pen always have a fixed width while lines drawn with a geometric pen can be scaled—they may appear wider or narrower depending on the current world transformation. For more information about the world transformation, see Chapter 73, “Coordinate Spaces and Transformations.”
You can create a cosmetic pen by calling the CreatePen, CreatePenIndirect, and ExtCreatePen functions. You can retrieve one of the three “stock” cosmetic pens (which are managed by the Window Manager) if you call the GetStockObject function. And, you can create a geometric pen by calling the ExtCreatePen function.
Once you've created a pen (or obtained a handle identifying one of the Window Managers stock pens), you can select it into your application's device context by calling the SelectObject function. From this point on, any line drawing operations in the client-area of your application's window will use this pen.