程序如下:
void CMainFrame::OnExample(UINT nCmdID) //nCmdID为用户选择的菜单的ID
{
if (nCmdID == m_nCurrentExample)
return; // already selected // Set the child window ID of the active view to AFX_IDW_PANE_FIRST.
// This is necessary so that CFrameWnd::RecalcLayout will allocate
// this "first pane" to that portion of the frame window's client
// area not allocated to control bars. Set the child ID of
// the previously active view to some other ID; we will use the
// command ID as the child ID.
CView* pOldActiveView = GetActiveView();
::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, m_nCurrentExample);
//上句不懂,上面的英文也没看懂,我注释掉也未发现什么异常 CRuntimeClass* pNewViewClass;
switch (nCmdID)
{
case ID_STRINGLIST:
pNewViewClass = RUNTIME_CLASS(CStringListView);
break;
case ID_TYPEDLIST:
pNewViewClass = RUNTIME_CLASS(CTypedPtrListView);
break;
case ID_INTLIST:
pNewViewClass = RUNTIME_CLASS(CIntListView);
break;
case ID_DWORDARRAY:
pNewViewClass = RUNTIME_CLASS(CDWordArrayView);
break;
case ID_TYPEDPTRARRAY:
pNewViewClass = RUNTIME_CLASS(CTypedPtrArrayView);
break;
case ID_POINTARRAY:
pNewViewClass = RUNTIME_CLASS(CPointArrayView);
break;
case ID_MAPSTRINGTOSTRING:
pNewViewClass = RUNTIME_CLASS(CMapStringToStringView);
break;
case ID_TYPEDPTRMAP:
pNewViewClass = RUNTIME_CLASS(CTypedPtrMapView);
break;
case ID_MAPDWORDTOMYSTRUCT:
pNewViewClass = RUNTIME_CLASS(CMapDWordToMyStructView);
break;
default:
ASSERT(0);
return;
} // create the new view
CCreateContext context;
context.m_pNewViewClass = pNewViewClass;
context.m_pCurrentDoc = GetActiveDocument();
CView* pNewView = STATIC_DOWNCAST(CView, CreateView(&context));
if (pNewView != NULL)
{
// the new view is there, but invisible and not active...
pNewView->ShowWindow(SW_SHOW);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
RecalcLayout();
m_nCurrentExample = nCmdID; // finally destroy the old view...
pOldActiveView->DestroyWindow();
}
}
void CMainFrame::OnExample(UINT nCmdID) //nCmdID为用户选择的菜单的ID
{
if (nCmdID == m_nCurrentExample)
return; // already selected // Set the child window ID of the active view to AFX_IDW_PANE_FIRST.
// This is necessary so that CFrameWnd::RecalcLayout will allocate
// this "first pane" to that portion of the frame window's client
// area not allocated to control bars. Set the child ID of
// the previously active view to some other ID; we will use the
// command ID as the child ID.
CView* pOldActiveView = GetActiveView();
::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, m_nCurrentExample);
//上句不懂,上面的英文也没看懂,我注释掉也未发现什么异常 CRuntimeClass* pNewViewClass;
switch (nCmdID)
{
case ID_STRINGLIST:
pNewViewClass = RUNTIME_CLASS(CStringListView);
break;
case ID_TYPEDLIST:
pNewViewClass = RUNTIME_CLASS(CTypedPtrListView);
break;
case ID_INTLIST:
pNewViewClass = RUNTIME_CLASS(CIntListView);
break;
case ID_DWORDARRAY:
pNewViewClass = RUNTIME_CLASS(CDWordArrayView);
break;
case ID_TYPEDPTRARRAY:
pNewViewClass = RUNTIME_CLASS(CTypedPtrArrayView);
break;
case ID_POINTARRAY:
pNewViewClass = RUNTIME_CLASS(CPointArrayView);
break;
case ID_MAPSTRINGTOSTRING:
pNewViewClass = RUNTIME_CLASS(CMapStringToStringView);
break;
case ID_TYPEDPTRMAP:
pNewViewClass = RUNTIME_CLASS(CTypedPtrMapView);
break;
case ID_MAPDWORDTOMYSTRUCT:
pNewViewClass = RUNTIME_CLASS(CMapDWordToMyStructView);
break;
default:
ASSERT(0);
return;
} // create the new view
CCreateContext context;
context.m_pNewViewClass = pNewViewClass;
context.m_pCurrentDoc = GetActiveDocument();
CView* pNewView = STATIC_DOWNCAST(CView, CreateView(&context));
if (pNewView != NULL)
{
// the new view is there, but invisible and not active...
pNewView->ShowWindow(SW_SHOW);
pNewView->OnInitialUpdate();
SetActiveView(pNewView);
RecalcLayout();
m_nCurrentExample = nCmdID; // finally destroy the old view...
pOldActiveView->DestroyWindow();
}
}
解决方案 »
- 对话框中添加菜单
- CInternetSession的OpenURL方法,如果是文件协议,且路径中包含空格就会失败!!
- USHORT RtlUshortByteSwap(IN USHORT Source) 用过这个函数的人请进
- 急求助!!如何能实现无需smtp服务器发送邮件?
- CWnd的子类化成员函数SubclassDlgItem()具体的功能是什么?
- 有看过《Visual C++程序员实用大全》的吗?不知道这书怎么样啊?
- 谁知道有方便的方法来重命名注册表的键名?
- 哪位能给我一个简单的dde的例子
- 学习MFC哪本书比较好呀
- ●●如何增大listbox控件的宽度”●●
- 让菜单变灰和工具栏变灰
- 在VC++中打开.txt文件,我想直接调用记事本,用什么方法好
//上句不懂,上面的英文也没看懂,我注释掉也未发现什么异常
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = (CView*)GetDlgItem(dwViewID);
if (pNewActiveView == NULL)
{
switch(dwViewID)
{
case VIEW_REAGENT_CHEMINFO:
pNewActiveView = (CView*)new CChemInfo;
break;
case VIEW_REAGENT_STORAGE:
pNewActiveView = (CView*)new CChemicalsView;
break;
case VIEW_REAGENT_INUSE:
pNewActiveView = (CView*)new CInuseView;
break;
case VIEW_REAGENT_ONORDER:
pNewActiveView = (CView*)new COnOrderView;
break;
case VIEW_SUPPLIER:
pNewActiveView = (CView*)new CSupplierView;
break;
case VIEW_SAMPLELOG:
pNewActiveView = (CView*)new CSampleLogView;
break;
}
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
this, dwViewID, &context);
pNewActiveView->OnInitialUpdate();
} SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW); if(pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CChemInfo))
dwViewID=VIEW_REAGENT_CHEMINFO;
if(pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CChemicalsView))
dwViewID=VIEW_REAGENT_STORAGE;
if(pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CInuseView))
dwViewID=VIEW_REAGENT_INUSE;
if(pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(COnOrderView))
dwViewID=VIEW_REAGENT_ONORDER;
if(pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CSupplierView))
dwViewID=VIEW_SUPPLIER;
if(pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CSampleLogView))
dwViewID=VIEW_SAMPLELOG; pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(dwViewID);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
RecalcLayout();
pNewActiveView->SetWindowPos(&wndBottom, 0, 0, 0, 0,
SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
}