Color: GDI provides a hardware
independent color interface. We supply the absolute color code, and the GDI
maps that code to a suitable color or color combination on computer’s video
display.
Ø SetTextColor() is a CDC class member function and
it specifies the color in which the text should be displayed.
Ø SetBkColor()is a CDC class member function and
it specifies the background color.
Ø RGB() function is used to specify color
combination.
Ø We can
create our own pen & brush with specific color combination for drawing
text.
CBrushb(RGB(255,0,0));//Brush with
red color.
CPenp(RGB(0,255,0));//Pen with blue
color.
SelectObject(&obj) is used to
select appropriate pen or brush for drawing purpose.
Ex:
Void OnPaint()
{
CPaintDCd(this);
d.SetTextColor(RGB(255,0,0));
d.SetBkColor(RGB(0,0,255));
d.TextOut(100,100,”Hello”);
CBrushb(RGB(255,0,0));
CPenp(RGB(0,255,0));
d.SelectObject(&b);
d.SelectObject(&p);
d.Ellipse(25,25,100,100);
}
Font: Three types of fonts are supported by windows:
Ø Raster Fonts:Can be
displayed fast, but cannot be compressed or expanded to an arbitrary size.
Ø Stock Fonts: Defined as
a series of line segments in a ‘Connect-the-dot’ format. Can be compressed or
expanded to arbitrary size but suffers from poor quality.
Ø True Fonts: Best and
can be used in flexible manner. Some true fonts are Times New Roman, Arial,
Arial Italic, Courier New etc.
CreateFont() method is used to create a new
font:
Syntax:
CreateFont(Height,Width,Escapement,Orientation,Weight,Italic,Underline,
StrickOut,CharSet,OutPrecision,ClipPrecision,Quality,PitchAndFamily,lpszFacename)
Height: Height of character in pixel.
Width:
Width of character in pixel.
Escapment: Angle between the Escapment vector and X-axis (0-180)
Orientation:Specify orientation of text (0-Horizontal (W), 1-Verticle (Σ))
Weight: Specify thickness of character. (FW_BOLD, FW_THIN, FW_ULTRATHIN, etc)
.
Italic: 0/1 Underline: 0/1 StrickOut: 0/1 CharSet: DEFAULT_CHARSET
OutPrecision,ClipPrecision,Quality,PitchAndFamilyare set to 0,used for
alignment of text.
lpszFaceName: Times New Roman, Arial, Arial Italic, Courier New etc.
Ex:
Void OnPaint()
{
CPaintDCd(this);
CFontMyfont;
Myfont.CreateFont(50 ,30 ,0 ,0 ,FW_BOLD ,1 ,1 ,0 , DEFAULT_CHARSET, 0 ,0 ,0 ,0
,”Arial”);
d.SelectObject(&Myfont);
d.TextOut(100,100,”Hello”);
}
No comments:
Write comments