我用SDI在view区添加了几个对话框,方法是
void CKitView::OnInitialUpdate() 
{
CView::OnInitialUpdate();
 m_dlg.Create(IDD_FRONT_QC,this);
 m_dlg.ShowWindow(SW_SHOW);
}
由于我在view区的左边用的是类outlook形式的,所以对话框不能完全占据wiew区,请问我怎么设置dialog的位置了?

解决方案 »

  1.   

    用ForView
    切换视图:
    bool CAMComDoc::SwitchToView(CRuntimeClass *pNewViewClass)
    { int row, col;
    row=0;col=1;
    CMDIFrameWnd* pMainWnd = (CMDIFrameWnd*)AfxGetMainWnd();
    // Get the active MDI child window.
    CMDIChildWnd* pChild = (CMDIChildWnd*)pMainWnd->MDIGetActive();
    // Get the active view attached to the active MDI child window.
    CView* pOldActiveView = pChild->GetActiveView();
    CSplitterWnd* pSplitter = (CSplitterWnd *)pOldActiveView->GetParent();
    // ASSERT(pSplitter->IsChildPane(pOldActiveView, row, col));


    pOldActiveView=(CView*)pSplitter->GetPane(row,col);
    // If we're already displaying this kind of view, no need to go further.
    if (pOldActiveView->IsKindOf(pNewViewClass))
    return TRUE;

    CRect viewrect;
    pOldActiveView->GetWindowRect(&viewrect); // set flag so that document will not be deleted when view is destroyed

       
    m_bAutoDelete = FALSE;    
    // Delete existing view 
    CCreateContext context;
    context.m_pNewViewClass = pNewViewClass;
    context.m_pCurrentDoc = this; pOldActiveView->DestroyWindow(); m_bAutoDelete=TRUE;

    // set flag back to default 
    // Create new view                      
    // POSITION pos=::AfxGetApp()->GetFirstDocTemplatePosition();

    context.m_pNewDocTemplate =this->GetDocTemplate();// ::AfxGetApp()->GetNextDocTemplate(pos);
    context.m_pLastView = NULL;
    // context.m_pCurrentFrame = NULL;
    if (!pSplitter->CreateView(row, col, pNewViewClass, viewrect.Size(),
            &context))
    return FALSE;
    CView* pNewView = (CView *)pSplitter->GetPane(row, col);
    pNewView->OnInitialUpdate();
    // Set active  pSplitter->GetParentFrame()->SetActiveView(pNewView);

    pSplitter->RecalcLayout(); 
    pNewView->SendMessage(WM_PAINT); 
    return TRUE;
    }
      

  2.   

    谢谢yintongshun(左岸思雨),不过我想用CView,不用CFormView啊
      

  3.   

    同意 flyelf(空谷清音) 
    用MoveWindow()或者SetWindowPos()
      

  4.   

    现在可以在OnInitialUpdata添加多个diaolig了,可是怎么控制她们的出现了?就是点击左边右边出现对应的dialog,我的代码总是报错啊
    void CPatchView::OnInitialUpdate() 
    {
    CView::OnInitialUpdate();
    CRect rect;
             GetClientRect(&rect);
    dlgUser.Create(IDD_DLG_USER,this);
    dlgUser.ShowWindow(SW_SHOW);
    dlgUser.MoveWindow(rect);
    dlgLog.Create(IDD_DLG_LOG,this);
    dlgLog.ShowWindow(SW_HIDE);
    dlgLog.MoveWindow(rect);
    }
    void CPatchView::SetCurrentView(CString str)
    {
    if (str.CompareNoCase("日志管理")==0)
    {
                        ASSERT(dlgUser);
     ASSERT(dlgLog);
                         dlgUser.ShowWindow(SW_HIDE);
                         dlgLog.ShowWindow(SW_SHOW);
    }
    else
    {
     ASSERT(dlgUser);
     ASSERT(dlgLog);
                       dlgUser.ShowWindow(SW_SHOW);
     dlgLog.ShowWindow(SW_HIDE);
    }
    }
    这是我的代码,可是进入SetCurrentView时候会报错winocc.cpp错误。debug Assertion
    我看了一下源码,是dlgUser.ShowWindow(SW_HIDE);报错。请问是什么问题啊?
      

  5.   

    你可以用CArray的对象把这些对话框的的指针保存起来,在需要对其进行操作的时候,只要根据索引找到对应对话框的指针就好了!
      

  6.   

    我感觉我不是找不到对话框的指针,而是觉得dlgUser.ShowWindow(SW_HIDE);这句话不能用在这里
      

  7.   

    我有换了一种写法
             UINT pageID [] = {IDD_DLG_LOG, IDD_DLG_USER};
    CDialog* pDlg;
    for (int i = 0; i < 2; i++)
    {
    switch (i)
    {
    case 0:
    pDlg = new CDlgUser();
    break;

    case 1:
    pDlg = new CDlgLog();
    break;
    default:
    ASSERT (FALSE);
    }
    pDlg->Create (pageID[i], this);
    pDlg->ModifyStyle (WS_CAPTION|WS_BORDER, 0);
    m_arrayForms.Add (pDlg);               CRect rect;
                   GetClientRect(&rect);
          pDlg->MoveWindow(rect); }
    m_pActivePage = m_arrayForms [0];
    m_pActivePage->ShowWindow (SW_SHOW);
    可是在pDlg->Create (pageID[i], this);这句话报错
      

  8.   

    我把我的代码贴出来,大家帮我看看什么原因:
    void CPatchView::OnInitialUpdate() 
    {
    CView::OnInitialUpdate(); UINT pageID [] = {IDD_DLG_USER,IDD_DLG_LOG};
    CDialog* pDlg; for (int i = 0; i < 2; i++)
    {
    switch (i)
    {
    case 0:
    pDlg = new CDlgUser();
    break;

    case 1:
    pDlg = new CDlgLog();
    break;
    default:
    ASSERT (FALSE);
    }
    ASSERT(pageID[i]);
    pDlg->Create (pageID[i], this);
    pDlg->ModifyStyle (WS_CAPTION|WS_BORDER, 0);
    m_arrayForms.Add (pDlg); CRect rect;
    GetClientRect(&rect);
    pDlg->MoveWindow(rect); }
    m_pActivePage = m_arrayForms [0];
    m_pActivePage->ShowWindow (SW_SHOW);
    }
     
    }void CPatchView::SetCurrentView(UINT m_uiCurrView)
    {    UINT uiPage;
        CDialog* pPage =NULL;
        pPage = m_arrayForms [m_uiCurrView];
    ASSERT (pPage != NULL);
    ASSERT (m_pActivePage != NULL); if (pPage != m_pActivePage)
    {
    m_pActivePage->ShowWindow (SW_HIDE);
    pPage->ShowWindow (SW_SHOW);
    m_pActivePage = pPage;
    }
    m_nActivePage = uiPage;
    }
    目前可以显示,但是调用SetCurrentView时候,执行到
    pPage = m_arrayForms [m_uiCurrView];时。就报错了afxtempl.cppd的262行debug assertion。请大家帮我分析一下啊。谢谢