This section explains the fourth step in writing Hello: paint text in the window.
·To paint text in Hello's window:
1.Add the OnPaint handler function for processing WM_PAINT messages to HELLO.CPP:
void CMainWindow::OnPaint()
{
CString s = "Hello, Windows!";
CPaintDC dc( this );
CRect rect;
GetClientRect( rect );
dc.SetTextAlign( TA_BASELINE | TA_CENTER );
dc.SetBkMode( TRANSPARENT );
dc.TextOut( rect.right / 2, rect.bottom / 2, s, s.GetLength() );
}
Put the OnPaint member function in your HELLO.CPP file with other
CMainWindow member functions.
2.You already added the ON_WM_PAINT macro to Hello's message map. Its line in the message map looks like this:
ON_WM_PAINT()
Requirements for naming the OnPaint member function and for the macro name are discussed below.
To continue the tutorial, see “Add an About Dialog Box” on page 105. For more information on the code you just added, see the following discussion.