Google Ads

Thursday, December 3, 2009

INTERFACE OBJECTS



GRAPHICS DEVICE INTERFACE OBJECTS



1. Run AppWizard to generate the third project.

2. Use ClassWizard to override the OnPrepareDC function in the thirdView class.

void thirdView :: OnPrepareDC (CDC* pDC, CPrintInfo* pInfo)

{

pDC -> SetMapMode (MM_ANISOTROPHIC);

pDC -> SetWindowExt (1440, 1440);

pDC -> SetViewPortExt (

pDC -> GetDeviceCaps (LOGPIXELSX),

pDC -> GetDeviceCaps (LOGPIXELSY));

}

3. Add a private ShowFont helper function to the view class. (thirdView.h)

private:

void ShowFont (CDC* pDC, int& nPos, int nPoints);

then add the function in thirdView.cpp

void thirdView :: ShowFont (CDC* pDC, int& nPos, int nPoints)

{

TEXTMETRIC tm;

CFont fontText;

CString strText;

CSize sizeText;

fontText.CreateFont (nPoints * 20, 0,0,0,400,FALSE,FALSE,0,

ANSI_CHARSET, OUT_DEFAULT_PRECIS,

CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, “Arial”);

CFont* pOldFont = (CFont* ) pDC -> SelectObject (&fontText);

pDC -> GetTextMetrics (&tm);

TRACE (“points = %d, tmHeight = %d, tmExternalLeading = %d”,”tmExternalLeading = %d\n”, nPoints, tm.tmHeight, tm.tmInternalLeading, tm.tmExternalLeading);

strText.Format(“This is %d – point Arial”,nPoints);

sizeText = pDC -> GetTextExtent (strText);

TRACE(“string width = %d, string height = %d\n”, sizeText.cx, sizeText.cy);

pDC -> TextOut (0,nPos, strText);

pDC -> SelectObject (pOldFont);

nPos -= tm.tmHeight + tm.tmExternalLeading;

}

4. Edit the OnDraw function in thirdView.cpp

void thirdView :: OnDraw (CDC* pDC)

{

int nPosition = 0;

for ( int i = 6; i <= 24; i +=2)

{

ShowFont (pDC, nPosition, i);

}

TRACE (“LOGPIXEL = %d, LOGPIXEL = %d\n”,

pDC -> GetDeviceCaps (LOGPIXELSX),

pDC -> GetDeviceCaps (LOGPIXELSY));

TRACE (“HORZSIZE = %d, VERTSIZE = %d\n”,

pDC -> GetDeviceCaps (HORZSIZE),

pDC -> GetDeviceCaps (VERTSIZE));

TRACE (“HORZRES = %d, VERTRES = %d\n’,

pDC -> GetDeviceCaps ( HORZRES),

pDC -> GetDeviceCaps (VERTRES));

}

5. Build and run the program.


No comments:

Post a Comment