2

In an MFC application, there is a dockable pane which is divided into 2 rows using CSplitterWndEx. I'm trying to add two dialogs using this splitter:

BOOL CPaneSplitter::AddWindow(int row, int col, CWnd* pWnd , CString clsName ,
DWORD dwStyle,DWORD dwStyleEx, SIZE sizeInit)
{

    // set the initial size for that pane
    m_pColInfo[col].nIdealSize = sizeInit.cx;
    m_pRowInfo[row].nIdealSize = sizeInit.cy;
    ASSERT(pWnd->m_hWnd == NULL);       // not yet created
    // Create with the right size (wrong position)
    CRect rect(CPoint(0,0), sizeInit);
    if (!pWnd->CreateEx(dwStyleEx,clsName,NULL,dwStyle,rect,this,IdFromRowCol(row,                    col)))
    { 
        return FALSE;
    } 
 }

Edit:

And here is the code where the splitter is created:

int CSplitePane::OnCreate(LPCREATESTRUCT lp)
{
    if(CDockablePane::OnCreate(lp)==-1)
        return -1;
    m_wndSplitter.CreateStatic(this,2,1);


    DWORD dwStyle = WS_CHILD | WS_VISIBLE ;
    if(!m_wndSplitter.AddWindow(0,0,&m_ChildDlg1,_T("My_Dailog_Pane"),dwStyle,0,CSize(100,100)))
        return -1;  
    m_ChildDlg1.ShowWindow(SW_SHOWDEFAULT);

    dwStyle = WS_CHILD | WS_VISIBLE | LVS_REPORT  | LVS_SHAREIMAGELISTS;
    if(!m_wndSplitter.AddWindow(1,0,&m_wndList,WC_LISTVIEW,dwStyle,0,CSize(100,100)))
        return -1; 

        m_wndList.ModifyStyle(LVS_TYPEMASK, LVS_ICON);

    return 0 ;
}
void CSplitePane::OnSize(UINT nType,int cx,int cy)
{
    CDockablePane::OnSize(nType,cx,cy);
    int cyTlb =0;// m_wndToolbar.CalcFixedLayout(FALSE, TRUE).cy;
    CRect rect;
    GetClientRect(rect);
    m_ChildDlg1.SetWindowPos(NULL,rect.left, rect.top, rect.Width(),rect.Height(),SWP_NOACTIVATE|SWP_NOZORDER);

    m_wndSplitter.SetWindowPos(NULL,rect.left
    , rect.top + cyTlb
    , rect.Width()  , rect.Height() - cyTlb , SWP_NOZORDER | SWP_NOACTIVATE);

}

This method accepts CWnd as an argument but I pass the dialog itself so when the application is run the pane is divided but dialog controls are not there.

So my question is: Is it possible to add a CDialog object to a pane using CSplitterWndEx?

ali
  • 529
  • 4
  • 26

2 Answers2

1

Maybe what you are looking for is CPaneDialog. Check out the SetPaneSize example from the VS 2008 Feature Pack Samples. Excerps from the sample:

    void CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
            ...

        if (!m_wndDlgBar.Create (_T("DialogBar"), this, TRUE,
                         MAKEINTRESOURCE (IDD_DLG_BAR), 
                         WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI, 
                         ID_VIEW_DLGBAR))
        {
            TRACE0("Failed to create Dialog Bar\n");
            return FALSE;      // fail to create
        }

        m_wndDlgBar.EnableDocking(CBRS_ALIGN_ANY);
        m_wndDlgBar.DockToWindow (&m_wndWorkSpace, CBRS_ALIGN_BOTTOM);

        ...
    }

void CMainFrame::OnViewDialogBar() 
{
    ShowPane (&m_wndDlgBar, !(m_wndDlgBar.IsVisible ()), FALSE, TRUE);
    RecalcLayout ();
}

...
thomiel
  • 2,467
  • 22
  • 37
  • Thanks, If I use the above AddWindow method on CPaneDialog, the CWnd is created but nothing is shown on the dialog and when mouse moves inside the dialog it crashes in HitTest method: CDockingManager* pDockManager = afxGlobalUtils.GetDockingManager(GetDockSiteFrameWnd()); ENSURE(pDockManager != NULL || afxGlobalUtils.m_bDialogApp); And if I use CPaneDialog "Create" method to create the dialog then it crashes in GetPane method: CWnd* pView = GetDlgItem(IdFromRowCol(row, col)); ASSERT(pView != NULL); I tried tabbed bar for panes instead of putting dialogs in one pane – ali Mar 14 '14 at 10:33
  • I think you forgot some code to integrate the CPaneDialog properly. I really recommend examining the SetPaneSize example to see how it works. – thomiel Mar 14 '14 at 12:18
  • Hello. I cannot find that example. Where should I get it? (I use VS2013). Do you have the example and perhaps could send me? – manatttta Apr 21 '15 at 21:03
  • It's from the VS2008 Features Pack. There was an issue when installing VS SP1 and Features Pack in the wrong order, leading to the samples not being installed to your documents folder, if I remember correctly. – thomiel Apr 22 '15 at 12:50
1

What about using CFormView derived class?

JohnCz
  • 1,613
  • 1
  • 9
  • 9