背景:三个VIEW类view1、view2、infor派生自CFormView,窗口被分为两列,分别显示view1(左视)view2(右视),现在要响应左视的点击切换右视为infor:
以下是我抄的“Richard Stringer ”的代码:BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: 在此添加专用代码和/或调用基类
myspl.CreateStatic(this,1,2);
myspl.CreateView(0,0,RUNTIME_CLASS(view1),CSize(163),pContext);
myspl.CreateView(0,1,RUNTIME_CLASS(view2),CSize(1000),pContext);
return TRUE;//CFrameWnd::OnCreateClient(lpcs, pContext);
}void CMainFrame::ChangeView(CString nview)
{
SetActiveView((CView*)myspl.GetPane(0,1));
int nForm=IDD_INFOR; //IDD_INFOR为视infor的对话框ID
CView* pOldActiveView = GetActiveView(); // save old view
CView* pNewActiveView = (CView*)GetDlgItem(nForm); // get new view
if (pNewActiveView == NULL)
{
switch(nForm) // these IDs are the dialog IDs of the view but can use anything
{
case IDD_INFOR:
pNewActiveView = (CView*)new infor;
break;
} CCreateContext context; // attach the document to the new view
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, // and the frame
this, nForm, &context);
pNewActiveView->OnInitialUpdate();
} SetActiveView(pNewActiveView); // change the active view
pNewActiveView->ShowWindow(SW_SHOW); // show the new window
pOldActiveView->ShowWindow(SW_HIDE); // hide the old
::SetWindowWord(pNewActiveView->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST); // gotta have it
RecalcLayout(); // adjust frame
delete pOldActiveView; // kill old view
}
运行时context.m_pCurrentDoc = pOldActiveView->GetDocument();通不过,将这行注释掉则pNewActiveView->OnInitialUpdate();通不过,请指教!还有一个问题,为何很多兄弟在切换视图时要用到SetDlgCtrlID()这个函数?
以下是我抄的“Richard Stringer ”的代码:BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: 在此添加专用代码和/或调用基类
myspl.CreateStatic(this,1,2);
myspl.CreateView(0,0,RUNTIME_CLASS(view1),CSize(163),pContext);
myspl.CreateView(0,1,RUNTIME_CLASS(view2),CSize(1000),pContext);
return TRUE;//CFrameWnd::OnCreateClient(lpcs, pContext);
}void CMainFrame::ChangeView(CString nview)
{
SetActiveView((CView*)myspl.GetPane(0,1));
int nForm=IDD_INFOR; //IDD_INFOR为视infor的对话框ID
CView* pOldActiveView = GetActiveView(); // save old view
CView* pNewActiveView = (CView*)GetDlgItem(nForm); // get new view
if (pNewActiveView == NULL)
{
switch(nForm) // these IDs are the dialog IDs of the view but can use anything
{
case IDD_INFOR:
pNewActiveView = (CView*)new infor;
break;
} CCreateContext context; // attach the document to the new view
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, // and the frame
this, nForm, &context);
pNewActiveView->OnInitialUpdate();
} SetActiveView(pNewActiveView); // change the active view
pNewActiveView->ShowWindow(SW_SHOW); // show the new window
pOldActiveView->ShowWindow(SW_HIDE); // hide the old
::SetWindowWord(pNewActiveView->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST); // gotta have it
RecalcLayout(); // adjust frame
delete pOldActiveView; // kill old view
}
运行时context.m_pCurrentDoc = pOldActiveView->GetDocument();通不过,将这行注释掉则pNewActiveView->OnInitialUpdate();通不过,请指教!还有一个问题,为何很多兄弟在切换视图时要用到SetDlgCtrlID()这个函数?
解决方案 »
- CWnd * pWnd//怎么可以接受一个this指针(是ClistView)???
- 程序执行系统重启动作,如何在重启后回到程序继续执行!
- 怎么样能在win7下实现NDIS中间层网络驱动的动态加载?
- volatile变量
- 使用MFC的ODBC去连接ACCESS数据库后,怎样断开与数据库和数据源的连接。
- 程序中创建的控件的ID号怎么分配?
- ================怎么关掉一个动态创建的控件================
- 各位高手,在Class中将函数申明为private,有什么意义?
- 这样启动另一个系统?
- 高分请教:异步socket,如何获取完整的http响应,详见内容
- 如何根据给定的两点m_FromPoint和m_ToPoint来画出一条在m_ToPoint节点带箭头的线?谢谢!
- 初学MFC的问题?!建立的对话框程序中FileView中的*.cpp *Dlg.cpp还有StdAfx.cpp都是干什么用的?还有后台.....
,谢谢了!