Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
Resources » Articles » General »
Creating Pen and Brush in VC++
|
Creating Brush and Pen in VC++ using MFC Brush and Pen are two components for outputting text and graphics. The selection of a particular brush makes the outline being drawn using that brush. The selection of a pen makes the output of text and graphics by using a particular style. To use a particular brush or pen we have to associate that brush or pen with the device context.
Defining a Brush:-
CBrush:- An object of this component represents a brush with a particular color. The constructor of this component takes the color in RGB format as its argument.
CBrush redBrush(RGB(255,0,0));
Associating Brush with device context:-
To use a brush for outputting, it should be associated with the device context. Syntax:-
[devicecontext object].SelectObject(&brush object); This function associates the brush with the device context.
CBrush greenBrush(0,255,0); CClientDC dc(this); dc.SelectObject(&greenBrush);
Defining a Pen:-
CPen:- An object of this component represents pen with a particular style, thickness and color. The constructor of this component takes three arguments representing the style, thickness and color. Syntax:-
CPen [pen object](style, thickness, color);
The style of the pen is represented by a set of predefined constants that begins with "PS_". The commonly used constants are as follows,
PS_SOLID (the style is "_______") PS_DASH (the style is "-------") PS_DOT (the style is ".......") PS_DASH_DOT (the style is "-.-.-.-")
The thickness of the pen is an integer representing width of the pen in pixels.
The color parameter is represented in RGB format
CPen redPen(PS_SOLID,4,RGB(255,0,0)); CPen bluePen(PS_DASH_DOT,3,RGB(0,0,255));
Associating pen to device context:-
To use a particular pen for outputting, it should be associated with the device context. Syntax:-
[devicecontext object].SelectObject(&pen object); This function associates the particular pen with the device context.
CPen bluePen(PS_DASH_DOT,3,RGB(0,0,255)); CClientDC dc(this); dc.SelectObject(&bluePen);
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|