下面这段代码切换客户区的时候总是闪烁,研究发现导致闪烁的是RecalcLayout函数,但如果去掉RecalcLayout函数,客户区就切换不了,怎么办啊?
void CMainFrame::SwitchToForm(int nForm)
{
CView* pOldActiveView = GetActiveView(); // save old view
CView* pNewActiveView = (CView*)GetDlgItem(nForm);  // get new view
if (pNewActiveView == NULL)     // if it hasn't been created yet
{                               // create it here
switch(nForm) // these IDs are the dialog IDs of the view but can use anything m_pDocument CXX0030: Error: expression cannot be evaluated{
case IDD_JZGL_FORM:
pNewActiveView = (CView*)new CJzGlView;
break;case IDD_DIALOGHYGL:
pNewActiveView = (CView*)new CHyGlView;
break;case IDD_JZGL_FORM1:
pNewActiveView = (CView*)new CQxWx;
break;default:
break;}CCreateContext context;       // attach the document to the new view
pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, // and the frame
this, nForm, &context);
}SetActiveView(pNewActiveView);
pNewActiveView->OnInitialUpdate();       
::SetWindowLong(pNewActiveView->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST);  // gotta have it
RecalcLayout(FALSE); // adjust frame
delete pOldActiveView; // kill old view    }
切换客户区的时候屏幕总闪烁。

解决方案 »

  1.   

    你本意是Swtich视图,但是代码却是重新建立视图(都是new,Create)。
    重建可不是就是简单调用OnPaint函数这么简单了。必定闪烁了。
      

  2.   

    你本意是Swtich视图,但是代码却是重新建立视图(都是new,Create)。
    重建可不是就是简单调用OnPaint函数这么简单了。必定闪烁了。 
    那怎么办,能给出方法吗?
      

  3.   

    用不着每切换一次就new一个,创建出来吧?做个全局的,第一次Create出来,后面就ShowWindow出来就可以了
      

  4.   

    先把之前的所有不需要显示的隐藏ShowWindow(SW_HIDE)
    要显示的显示ShowWindow(SW_SHOW)