Dashed and dotted lines with a pen width greater than 1 logical unit

A Simple Dash-Line Class


With the Windows API, you can only create a dash or dot pen when the pen width is 1.
This class permits you to work with virtual dash or dot pen with width bigger than 1.


You give the constructor the current dc, two different colors, the width of the pen and a
line type array of four integers. The constructor creates two PS_SOLID pens and draws a line
using the line type array.

 Type[4] = {20, 10, 10, 10};


Once you have created the CDashLine class, you can use the function MoveTo(x, y) and
LineTo(x, y) to draw a line between two points. The MoveTo() function resets the internal
type position and color index. The LineTo() function starts with the current type position
and color. Do not forget to save the current pen and restore it after using CDashLine. Do not
destroy the dc and use CDashLine after this!

Download source – 41 KB

More by Author

Must Read