Article ID: 201045
Article Last Modified on 11/21/2006
// data members
protected:
CRect m_Ellipse;
CRect m_Rectangle;
// initialization: replace existing contructor
CDrawWnd::CDrawWnd():
m_Ellipse(10, 10, 100, 100),
m_Rectangle(5, 5, 105, 105)
{
}
// painting: replace existing OnPaint
void CDrawWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
dc.Rectangle(m_Rectangle);
dc.Ellipse(m_Ellipse);
}
In CTextWnd:
// data members
protected:
CString m_Text;
// initialization: replace existing contructor
CTextWnd::CTextWnd():
m_Text("Text Window ")
{
}
// painting: replace existing OnPaint
void CTextWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect r(10, 10, 400, 50);
dc.DrawText(m_Text, r, DT_BOTTOM);
}
HMENU m_hDrawMenu; HMENU m_hTextMenu; HACCEL m_hDrawAccel; HACCEL m_hTextAccel;
HINSTANCE hInst = AfxGetResourceHandle(); m_hDrawMenu = ::LoadMenu(hInst, MAKEINTRESOURCE(IDR_DRAWTYPE)); m_hTextMenu = ::LoadMenu(hInst, MAKEINTRESOURCE(IDR_TEXTTYPE)); m_hDrawAccel = ::LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_DRAWTYPE)); m_hTextAccel = ::LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_TEXTTYPE));For ExitInstance():
int CNDVWApp::ExitInstance()
{
if (m_hDrawMenu != NULL)
FreeResource(m_hDrawMenu);
if (m_hDrawAccel != NULL)
FreeResource(m_hDrawAccel);
if (m_hTextMenu != NULL)
FreeResource(m_hTextMenu);
if (m_hTextAccel != NULL)
FreeResource(m_hTextAccel);
return CWinApp::ExitInstance();
}
void CNDVWApp::OnFileNewDraw()
{
CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
// create a new MDI child window
pFrame->CreateNewChild(
RUNTIME_CLASS(CDrawFrame), IDR_DRAWTYPE, m_hDrawMenu, m_hDrawAccel);
}
For OnFileNewText():
void CNDVWApp::OnFileNewText()
{
CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
// create a new MDI child window
pFrame->CreateNewChild(
RUNTIME_CLASS(CTextFrame), IDR_TEXTTYPE, m_hTextMenu, m_hTextAccel);
}
void CDrawWnd::OnDrawWiden()
{
m_Ellipse.InflateRect(10, 10);
m_Rectangle.InflateRect(10, 10);
Invalidate();
}
void CTextWnd::OnTextAdd()
{
m_Text += " Window";
Invalidate();
}
IDR_DRAWTYPE \nDraw\nDraw IDR_TEXTTYPE \nText\nText
BOOL CDrawFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIChildWnd::PreCreateWindow(cs) )
return FALSE;
HICON hWndIcon = ::LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_DRAWTYPE));
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.lpszClass = AfxRegisterWndClass(0, 0, 0, hWndIcon);
return TRUE;
}
BOOL CTextFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIChildWnd::PreCreateWindow(cs) )
return FALSE;
HICON hWndIcon = ::LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_TEXTTYPE));
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.lpszClass = AfxRegisterWndClass(0, 0, 0, hWndIcon);
return TRUE;
}
Keywords: kbarchitecture kbdocview kbhowto kbuidesign KB201045