我需要关于sdi动态切换视图的代码!
问题点数:20、回复次数:1Top
1 楼masterz(www.fruitfruit.com)回复于 2002-02-01 23:03:40 得分 20
Adding multiple views to an SDI application
1.build an normal SDI project
2.Add a new view class derived from CView
3.Add debug and non debug versions of the GetDocument() function
4.Add a public constructor
5.make the destructor provided by class wizard public
6.include the document class header file in the source file of the new view class
7.add a handler for the OnDraw event of the new view class
8include the header file of the new view class in MainFrm.cpp
9add two protected variables in the CMainFrame class
These variables will be pointers to the two view objects your application uses. Initialize these
pointers to NULL in the constructor of CMainFrame,as shown in the following
class CMainFrame:public CFrameWnd
{
...
protected:
CItalicsView* m_pItalicView;
CDefaultView* m_pDefaultView;
...
}
CMainFrame::CMainFrame()
{
m_pItalicsView=NULL;
m_pDefaultView=NULL;
}
10.add two menu selection to permit the application to switch between the two views.
11.add command handlers to CMainFrame for the two new menu items.
void CMainFrame::OnViewItalics()
{
CDocument* pDoc=GetActiveDocument();
if(NULL==m_pItalicView)
{
m_pDefaultView=(CDefaultView*)GetActiveView();
m_pItalicsView=new CItalicsView(NULL);
m_pItalicsView->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1);
}
pDoc->AddView(m_pItalicsView);
m_pItalicsView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_pDefaultView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
m_pItalicsView->ShowWindow(SW_SHOW);
m_pDefaultView->ShowWindow(SW_HIDE);
SetActiveView(m_pItalicsView);
pDoc->RemoveView(m_pDefaultView);
RecalcLayout();
}
void CMainFrame::OnViewDefault()
{
CDocument* pDoc=GetActiveDocument();
pDoc->AddView(m_pDefaultView);
m_pItalicsView->ShowWindow(SW_HIDE);
m_pDefaultView->ShowWindow(SW_SHOW);
m_pItalicsView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
m_pDefaultView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
SetActiveView(m_pDefaultView);
pDoc->RemoveView(m_pItalicsView);
RecalcLayout();
}
Top




