LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT Ps;
HDC hdc;
SIZE size;
TCHAR str[100]=TEXT("\0");
HFONT font;
HBRUSH hBrush;
TEXTMETRIC tm; int y=0; int x=0; int textlength; switch (msg)
{ case WM_PAINT://traps paint message
//output text using default font
hdc = BeginPaint(hwnd, &Ps); int hDCLast;
hDCLast=SaveDC(hdc);//save current device context
textlength=wsprintf(str,TEXT("Stock font"));
TextOut(hdc,0,y,str,textlength);
//select ANSI_FIXED_FONT and output text
GetTextMetrics(hdc,&tm);
y=y+tm.tmHeight;//calculate new vertical coordinate using text metric
hBrush=(HBRUSH)GetStockObject(ANSI_FIXED_FONT);
SelectObject(hdc,hBrush);
textlength=wsprintf(str,TEXT("ANSI_FIXED_FONT") );
TextOut(hdc,0,y,str,textlength);
//set text to colour red and output text
GetTextMetrics(hdc,&tm);
y=y+tm.tmHeight;
COLORREF newtextcolour;
newtextcolour=COLORREF RGB(255, 0, 0);
SetTextColor(hdc,newtextcolour);
textlength=wsprintf(str,TEXT("ANSI_FIXED_FONT, colour red") );
TextOut(hdc,x,y,str,textlength);
//set text background to colour blue and output text
GetTextMetrics(hdc,&tm);
y=y+tm.tmHeight;
COLORREF newbkcolour;
newbkcolour=COLORREF RGB(0, 0, 255);
SetBkColor(hdc,newbkcolour);
textlength=wsprintf(str, TEXT("ANSI_FIXED_FONT, colour red with blue background") );
TextOut(hdc,x,y,str,textlength);
//set text background to transparent and output text
GetTextMetrics(hdc,&tm);
y=y+tm.tmHeight;
SetBkMode(hdc,TRANSPARENT);
SelectObject(hdc,hBrush);
textlength=wsprintf(str,TEXT("ANSI_FIXED_FONT,colour red transparent background") );
TextOut(hdc,0,y,str,textlength);
//select font Ariel 20 and output text
GetTextMetrics(hdc,&tm);
y=y+tm.tmHeight;
font = CreateFont(20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("Ariel"));
SelectObject(hdc,font);
textlength=wsprintf(str,TEXT("ANSI_FIXED_FONT, colour red, transparent background,arial 20") );
TextOut(hdc,0,y,str,textlength);
//restore default font using saved value and output text
GetTextMetrics(hdc,&tm);
y=y+tm.tmHeight;
RestoreDC(hdc,hDCLast);
textlength=wsprintf(str,TEXT("stock font restored using SaveDC/RestoreDC") );
TextOut(hdc,x,y,str,textlength);
GetTextMetrics(hdc,&tm);
y=y+tm.tmHeight;//calculate new vertical coordinate using text metric
//select font times new romans 30 and output text int baseline;//used to caculate font baseline
font = CreateFont(30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("Times New Roman"));
SelectObject(hdc,font);
GetTextMetrics(hdc,&tm);
baseline=tm.tmAscent;
textlength=wsprintf(str,TEXT("times new roman 30 statement 1") );
TextOut(hdc,x,y,str,textlength);
GetTextExtentPoint32(hdc,str,lstrlen(str),&size);
x=x+size.cx;
//select font courier new 20 and output text int baselinecourier;
font = CreateFont(20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("Courier New"));
SelectObject(hdc,font);
GetTextMetrics(hdc,&tm);
baselinecourier=baseline-tm.tmAscent;
textlength=wsprintf(str, TEXT("Courier statement ") );
TextOut(hdc,x,y+baselinecourier,str,textlength);
GetTextExtentPoint32(hdc,str,lstrlen(str),&size);
x=x+size.cx;
//select font ariel 20 and output text int baselineariel;
font = CreateFont(10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,TEXT( "Ariel"));
SelectObject(hdc,font);
GetTextMetrics(hdc,&tm);
baselineariel=baseline-tm.tmAscent;
textlength=wsprintf(str, TEXT("ariel 10 statement 3 ") );
TextOut(hdc,x,y+baselineariel,str,textlength);