DC attributes, canvas properties

Every device context has attributes such as color, font, pen, and palette. GDI32­.DLL provides access functions for reading and modifying these attributes. In Visual Basic, canvas objects have properties. Table 7-2 shows how to work with these attributes by means of device contexts in Windows and canvas objects in Visual Basic.

For the most part, you can stick with the Basic Way for reading and modifying attributes. Canvas properties don’t always match up one to one, but they’re usually more convenient. In fact, about the only common task I’ve found that you can’t do with Visual Basic is use a brush (FillStyle) that consists of a bitmap. (After reading “The Windows Way of Painting,” page 390, you should be able to figure that out for yourself.)

Figure 7-2. The ICanvas interface hierarchy.

Picture- Form Printer Box Image Shape Line Screen
Properties
hDC x x x
Picture x x x
Image x x
MouseIcon, MousePointer x x x x
Font x x x
AutoRedraw x x
BackColor x x x
ForeColor x x x
FillColor x x x x
DrawMode x x x x x
DrawStyle, DrawWidth x x x
FillStyle x x x x
CurrentX, CurrentY x x x
Width, Height x x x x x x
Left, Top x x x x
Scale properties x x x
TwipsPerPixelX,
TwipsPerPixelY x x
Methods
Line, Circle, PSet x x x
Point x x
Cls x x
Print x x x
TextWidth, TextHeight x x x
ScaleX, ScaleY x x x
PaintPicture x x x

Table 7-1. Properties and methods of canvas objects.

Attribute Windows Way Basic Way
Background color GetBkColor and SetBkColor BackColor
Background mode GetBkMode and SetBkMode FontTransparent
Text color GetTextColor and SetTextColor ForeColor
Color palette CreatePalette, SelectPalette, and other palette functions Palette and PaletteMode.properties
Brush Brush creation functions and SelectObject FillColor and FillStyle.

(but no way to use bitmap brush)

Pen Pen creation functions and SelectObject DrawStyle and DrawWidth Color parameter of Line and Circle methods
Pen color Pen definition set by Pen creation functions
Pen position GetCurrentPosition, LineTo, and MoveTo functions Line method with Step, CurrentX, CurrentY
Drawing mode SetROP2 DrawMode
Font Font creation functions and SelectObject Font object
Mouse pointer SelectObject, CreateCursor, and other cursor functions MousePointer and MouseIcon
Clip and redraw state Various functions related to repainting, managing regions, and clipping ClipControls, AutoRedraw, and AutoSize
Scale SetMapMode ScaleMode
Window extent and origin GetWindowExtEx, SetWindowExtEx, GetWindowOrgEx, and SetWindowOrgEx ScaleLeft, ScaleTop, ScaleWidth, and ScaleHeight
Screen capabilities GetDeviceCaps Screen object

Table 7-2. Graphics properties in Windows and in Visual Basic.