small1Download: small1.zip
The application small1 is a simple MFC example, no
Document/View architecture, no special features, just a frame window
(MainFrm.cpp) enclosing a client window (ChildView.cpp). Most of the
modifications required are those in ChildView.cpp, namely the
response to a WM_PAINT message, which is handled by the
OnPaint message handler.
Here we find the size of the client window and format a text string that we display centered in the client window.
void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect win;
GetClientRect(&win);
CString str;
str.Format(_T("width %d height %d"), win.Width() , win.Height());
dc.DrawText(str,win,DT_CENTER | DT_SINGLELINE | DT_VCENTER);
// Do not call CWnd::OnPaint() for painting messages
}
You can control the size of the application window by making a few
changes to the CREATESTRUCT in the PreCreateWindow
method in MainFrm.cpp.
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
// specify requested main window size (includes frame)
cs.cx = 400;
cs.cy = 400;
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.lpszClass = AfxRegisterWndClass(0);
return TRUE;
}
Maintained by John Loomis, updated Sun Jan 28 16:51:29 2007