Jalaj

February 24, 2007

Pen Object in Device Context

Filed under: Visual Basic, WinAPI — Jalaj @ 7:43 am

We saw a lot of functions that draw geometrical shapes. But the problem is that you can’t change the color or width or the style of the pen. The exception to my previous statement is the SetDCPenColor function that can change the pen color associated with the device context, and which we already discussed it in one of previous post WinAPI : GetPixel Function. However, the function is supported only on Windows 200 and later so you cannot use the function if your intent is to develop supporting previous versions too. Is there any way out?

Pen in one of the many objects associated with a device context. When you draw something that requires a pen the device context uses the pen that is currently associated with it. Now that you want to change the way the device context should reproduce things, you need to create a relevant pen using the CreatePen function and associate the pen with the device context using SelectObject function which will remove the current pen definition and replace it with the pen that you need to use. We will discuss the above functions later, let’s first see everything related to a Pen

A Pen within itself is defined by following:
1. Pen Style - Defines how lines/curves are to be drawn, can be Solid, Null (Invisible), Dashed, Dotted, alternate Dash and Dots or alternate Dash and Double Dots.
2. Pen Width - Defines the width of the lines/curves to be drawn.
3. Pen Color - Defines the color in which lines/curves are to be drawn.

However, a Pen cannot make use of all the attributes as defined above. While all pens can define the color in which drawings are to be generated, each pen can only take advantage of one of the other two attributes. In this context, Pen can be classified into two types:

1. Geometrical Pen - These Pens cannot have any style other than Solid. They can render drawings in varying widths.
2. Cosmetic Pen - While these Pens can have different style associated with them, they cannot have width other than 1 pixel.

3 Comments »

  1. [...] Visual Basic — Jalaj @ 9:19 am Getting ahead from where we ended in previous post Pen Object in Device Context, let’s see how to create a pen and associate it with the device [...]

    Pingback by WinAPI : The CreatePen Function « Jalaj — February 26, 2007 @ 10:07 am

  2. [...] Pen Object in Device Context [...]

    Pingback by Just Looking Back « Jalaj — May 28, 2007 @ 6:25 am

  3. [...] http://jalaj.net/2007/02/25/winapi-the-createpen-function/ [...]

    Pingback by The Blog Revisited - 6 « Jalaj — October 31, 2007 @ 8:23 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.