笔者正在做一个“单文档多视图”程序,多视图是用静态方法创建的,InitView函数如下:
void CMainFrame::InitViews()
{
CDocument* pCurrentDoc = GetActiveDocument();
CView* pCurrentView = GetActiveView();
   
    // Initialize a CCreateContext to point to the active document.
    // With this context, the new view is added to the document
    // when the view is created in CView::OnCreate().
    CCreateContext newContext;
    newContext.m_pNewViewClass = NULL;
    newContext.m_pNewDocTemplate = NULL;
    newContext.m_pLastView = NULL;
    newContext.m_pCurrentFrame = this;
    newContext.m_pCurrentDoc = pCurrentDoc;
    
m_CurViewIndex = M_VIEW_HOME;

m_Views[M_VIEW_HOME] = pCurrentView;
m_Views[M_VIEW_SCHEDULER] = new CBTSchedulerView;
m_Views[M_VIEW_RUNNING] = new CBTCampaignRView;
m_Views[M_VIEW_UPCOMING] = new CBTCampaignUView;
m_Views[M_VIEW_FINISHED] =  new CBTCampaignFView;
m_Views[M_VIEW_SYS] = new CBTExplorerView;
m_Views[M_VIEW_FILE] = new CBTFileManagerView;
// m_Views[M_VIEW_DEVICE] = new CBTDevInfoView;    CRect rectViews; // gets resized later
pCurrentView->GetWindowRect(rectViews);
ScreenToClient(rectViews); for(int idx_view=1; idx_view<=M_VIEW_FILE; idx_view++) {
m_Views[idx_view]->Create(NULL, NULL, (AFX_WS_DEFAULT_VIEW & ~WS_VISIBLE),
// views are created with the style of AFX_WS_DEFAULT_VIEW
// In MFC 4.0, this is (WS_BORDER | WS_VISIBLE | WS_CHILD)
rectViews, this, AFX_IDW_PANE_FIRST+idx_view, &newContext);

m_Views[idx_view]->MoveWindow(rectViews); // When a document template creates a view, the WM_INITIALUPDATE
// message is sent automatically. However, this code must
// explicitly send the message, as follows.
m_Views[idx_view]->OnInitialUpdate();
}}
在视图切换时,调用切换函数OnItemSelected。
// active relative view selected
void CMainFrame::OnItemSelected(WPARAM wparam)
{
CString strSelected = m_wndWorkSpace.GetStrSelected(wparam);
if(strSelected.IsEmpty())
strSelected = m_wndWorkSpace2.GetStrSelected(wparam);
if(strSelected.IsEmpty())
return; // update caption bar.
m_wndCaptionBar2.SetText(strSelected); const int nIndex = GetStrIndex(strSelected);
if(nIndex<0 || nIndex>M_VIEW_FILE) return; // needn't changing views.

CView* pNewView = m_Views[nIndex];
if(nIndex==0) pNewView = m_Views[0];    CView * pOldView = GetActiveView();
CDocument * pDoc = GetActiveDocument();
    
    if ( !pOldView )    // No currently active view
        return;
    if ( pNewView == pOldView )    // Already there
        return;

    m_CurViewIndex = nIndex;    // Store the new current view's index
 
// exchange view window ID's so RecalcLayout() works
    UINT temp = ::GetWindowLong(pNewView->m_hWnd, GWL_ID);
    ::SetWindowLong(pOldView->m_hWnd, GWL_ID, ::GetWindowLong(pNewView->m_hWnd, GWL_ID));
    ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);    // Display and update the new current view - hide the old one    
    pOldView->ShowWindow(SW_HIDE);
    pNewView->ShowWindow(SW_SHOW);    SetActiveView(pNewView, TRUE);
    RecalcLayout();
    pNewView->Invalidate(TRUE);
}
视图切换没有问题,只是在如果改变主框架窗口大小(譬如最大化),则new出来的view大小仍然是创建时那么大,而没有覆盖整个client rect。
请问各位高手,如何实现各个活动的view能覆盖整个client rect区?谢谢

解决方案 »

  1.   

    不是十分清楚,但是我觉的你该在新建的VIEW类中相应主框架窗口重绘的消息,然后在获得它当前的客户区大小去改变你这个VIEW类的客户区大小;我觉你这个VIEW类中,创建的时候它的大小就不变了。
      

  2.   

    谢谢LUCIzm。
    我试着把创建时的大小改成(0,0,0,0),效果没有变化。如果每次重绘时都计算一遍view的位置和大小,试过了,是可以实现的。但是,未免太麻烦,请问各位高手,有更好的办法嘛?