#define IDW_ORDER_FORM 1
#define IDW_CUST_FORM 2void CMainFrame::ChangeForm(int nform)
{
CView* poldactiveview=GetActiveView();
CView* pnewactiveview=(CView*)GetDlgItem(nform);
if(pnewactiveview==NULL)
{
switch(nform)
{
case IDW_ORDER_FORM:
pnewactiveview=(CView*)new CProdView;
break;
case IDW_CUST_FORM:
pnewactiveview=(CView*)new CCustView;
break;
}
CCreateContext context;
context.m_pCurrentDoc=poldactiveview->GetDocument();
pnewactiveview->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,nform,&context);
pnewactiveview->OnInitialUpdate();
}
SetActiveView(pnewactiveview);
pnewactiveview->ShowWindow(SW_SHOW);
poldactiveview->ShowWindow(SW_HIDE);
if(poldactiveview->GetRuntimeClass()==RUNTIME_CLASS(CProdView))
poldactiveview->SetDlgCtrlID(IDW_CUST_FORM);
else
if(poldactiveview->GetRuntimeClass()==RUNTIME_CLASS(CCustView))
poldactiveview->SetDlgCtrlID(IDW_ORDER_FORM);
pnewactiveview->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
RecalcLayout();
}void CMainFrame::OnCustomer()
{
// TODO: Add your command handler code here
if(GetActiveView()->IsKindOf(RUNTIME_CLASS(CCustView)))
return;
ChangeForm(IDW_CUST_FORM);
}void CMainFrame::OnUpdateCustomer(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CCustView)));
}void CMainFrame::OnProduct()
{
// TODO: Add your command handler code here
if(GetActiveView()->IsKindOf(RUNTIME_CLASS(CProdView)))
return;
ChangeForm(IDW_ORDER_FORM);
}void CMainFrame::OnUpdateProduct(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CProdView)));
}
这段代码是想用来通过选择不同的菜单来切换不同的视图。
如果我的问题没有说清楚或还有什么需要知道的请各位提出来。忘记的说一下,这段代码有错误
运行时,首先打开的是IDW_ORDER_FORM视图,
当我第一次选择菜单中的IDW_CUST_FORM时运行正常,再选择IDW_ORDER_FORM时也能运行正常,但是当我再次选择IDW_CUST_FORM时就不能显示IDW_CUST_FORM视图了,仍然显示的是IDW_ORDER_FORM
分数在 VC/MFC Visual C++ 资源问题 里给!!!
#define IDW_CUST_FORM 2void CMainFrame::ChangeForm(int nform)
{
CView* poldactiveview=GetActiveView();
CView* pnewactiveview=(CView*)GetDlgItem(nform);
if(pnewactiveview==NULL)
{
switch(nform)
{
case IDW_ORDER_FORM:
pnewactiveview=(CView*)new CProdView;
break;
case IDW_CUST_FORM:
pnewactiveview=(CView*)new CCustView;
break;
}
CCreateContext context;
context.m_pCurrentDoc=poldactiveview->GetDocument();
pnewactiveview->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,nform,&context);
pnewactiveview->OnInitialUpdate();
}
SetActiveView(pnewactiveview);
pnewactiveview->ShowWindow(SW_SHOW);
poldactiveview->ShowWindow(SW_HIDE);
if(poldactiveview->GetRuntimeClass()==RUNTIME_CLASS(CProdView))
poldactiveview->SetDlgCtrlID(IDW_CUST_FORM);
else
if(poldactiveview->GetRuntimeClass()==RUNTIME_CLASS(CCustView))
poldactiveview->SetDlgCtrlID(IDW_ORDER_FORM);
pnewactiveview->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
RecalcLayout();
}void CMainFrame::OnCustomer()
{
// TODO: Add your command handler code here
if(GetActiveView()->IsKindOf(RUNTIME_CLASS(CCustView)))
return;
ChangeForm(IDW_CUST_FORM);
}void CMainFrame::OnUpdateCustomer(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CCustView)));
}void CMainFrame::OnProduct()
{
// TODO: Add your command handler code here
if(GetActiveView()->IsKindOf(RUNTIME_CLASS(CProdView)))
return;
ChangeForm(IDW_ORDER_FORM);
}void CMainFrame::OnUpdateProduct(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(GetActiveView()->IsKindOf(RUNTIME_CLASS(CProdView)));
}
这段代码是想用来通过选择不同的菜单来切换不同的视图。
如果我的问题没有说清楚或还有什么需要知道的请各位提出来。忘记的说一下,这段代码有错误
运行时,首先打开的是IDW_ORDER_FORM视图,
当我第一次选择菜单中的IDW_CUST_FORM时运行正常,再选择IDW_ORDER_FORM时也能运行正常,但是当我再次选择IDW_CUST_FORM时就不能显示IDW_CUST_FORM视图了,仍然显示的是IDW_ORDER_FORM
分数在 VC/MFC Visual C++ 资源问题 里给!!!
其中的一个视图的实现文件是:
// CustView.cpp : implementation file
//#include "stdafx.h"
#include "Order.h"
#include "CustView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CCustViewIMPLEMENT_DYNCREATE(CCustView, CRecordView)CCustView::CCustView()
: CRecordView(CCustView::IDD)
{
//{{AFX_DATA_INIT(CCustView)
m_pSet = NULL;
//}}AFX_DATA_INIT
}CCustView::~CCustView()
{
if (m_pSet)
delete m_pSet;
}void CCustView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCustView)
DDX_FieldText(pDX, IDC_ADDRESS, m_pSet->m_address, m_pSet);
DDX_FieldText(pDX, IDC_CITY, m_pSet->m_city, m_pSet);
DDX_FieldText(pDX, IDC_CUST_ID, m_pSet->m_cust_id, m_pSet);
DDX_FieldText(pDX, IDC_NAME, m_pSet->m_name, m_pSet);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCustView, CRecordView)
//{{AFX_MSG_MAP(CCustView)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CCustView diagnostics#ifdef _DEBUG
void CCustView::AssertValid() const
{
CRecordView::AssertValid();
}void CCustView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CCustView message handlersCRecordset* CCustView::OnGetRecordset()
{
if (m_pSet != NULL)
return m_pSet; m_pSet = new CCustSet(NULL);
m_pSet->Open(); return m_pSet;
}CCustSet* CCustView::GetRecordset()
{
CCustSet* pData = (CCustSet*) OnGetRecordset();
ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CCustSet)));
return pData;
}void CCustView::OnInitialUpdate()
{
BeginWaitCursor();
GetRecordset();
CRecordView::OnInitialUpdate();
if (m_pSet->IsOpen())
{
CString strTitle = m_pSet->m_pDatabase->GetDatabaseName();
CString strTable = m_pSet->GetTableName();
if (!strTable.IsEmpty())
strTitle += _T(":") + strTable;
GetDocument()->SetTitle(strTitle);
}
EndWaitCursor();
}
望指教!!!
还有:
你说的“视图切换网上有可以直接用的啊”在哪里有啊?