Avoiding Device Dependencies

Pen widths will vary according to the resolution of the display. The stock pens (and any pen created with a width of 0) are 1 pixel wide, which on a high-resolution display can result in very thin lines.

If you're working in MM_TEXT, you might want to obtain the width of the single- line window border by calling GetSystemMetrics with the SM_CXBORDER and SM_CYBORDER indexes. These values are appropriate for pen widths. You can also use one of the metric mapping modes and set specific physical widths for the pens your program needs to create.

Pen colors are also susceptible to device dependencies. If you develop a program on a color display and then run the program on a monochrome display, you can be in for some unpleasant surprises. Except for the PS_INSIDEFRAME style, Windows always uses pure colors for pens, and on a monochrome system, pens are either black or white. For instance, on your color EGA, you might be fond of magenta pens on a white background:

hPen = CreatePen (PS_SOLID, 1, RGB (255, 0, 255)) ;

But on a monochrome system, the pure color that is closest to magenta is white, so the pen will be invisible. If you want to use colored pens, be sure the sum of 2 times the red, 5 times the green, and 1 times the blue values is less than 1920 (half the maximum sum of the three primaries) for any pen that should default to black and greater than 1920 for any pen that should default to white.