· To display the messages on the screen, open the xxWelcomeView.cpp file. Add the lines
as shown. This code will centre your text (getting the window dimensions with the
GetWindowRect() method and the text with the GetDocument() method), colour half the
screen blue and add an ellipse filled with greeny-blue cross hatching.
// xxWelcomeView drawing
void xxWelcomeView::OnDraw(CDC* pDC)
{
xxWelcomeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rect;
GetWindowRect(&rect);
int x = rect.Width()/2;
int xx = rect.Width()/2;
int xxx = rect.Width()/2;
int y = rect.Height();
int yy = rect.Height()/2;
int yyy = rect.Height()- 20;
CBrush myBrush;
CBrush backBrush;
//Declare a pointer variable
//An error handler macro
//Find the Windows dimensions
//and create some variables to
//position text
// Construct brushes to do the
cross hatching and background
colour
// Then initialize and use them.
if(myBrush.CreateHatchBrush(HS_DIAGCROSS, RGB(0, 200, 240)))
{
CBrush* pOldBrush = pDC->SelectObject( &myBrush );
pDC->Ellipse(CRect(50, 100, 250, 250));
pDC->SelectObject( pOldBrush );
}
if(backBrush.CreateSolidBrush(RGB(0,0,250)))
{
CBrush* pOlderBrush = pDC->SelectObject (&backBrush);
pDC->Rectangle (x*2,y,x,0);
pDC-> SelectObject(pOlderBrush);
}
//Centre and display welcome_string
CSize size = pDC->GetTextExtent(pDoc->welcome_string);
x -= size.cx/2;
pDC->TextOut(x, 0, pDoc->welcome_string);
// TODO: add draw code for native data here
//Position and display enjoy_string
CSize size2 = pDC->GetTextExtent(pDoc->enjoy_string);
xx += (size2.cx/2 + 50);
pDC->TextOut(xx, yy, pDoc->enjoy_string);
}
No comments:
Post a Comment