c++mfcribbon-control

I want my dialog to behave like a dockable pane in MFC a ribbon based MDI application


I am creating a dialog, it's inherited from CDialogEx (dialog class name DockColorDlg), and create another class (ColorDockable) that's inheriting from the CDockablePane class. And in my ColorDockable class I am creating the instanced of the DockColorDlg (DockColorDlg m_wndDialog).

Now I am calling from my Mainfram.cpp and create the dockable window, when I am implementing this then it will work, but after few times or a few build it will not create the window.

calling from my Mainfrm.cpp:
    if (!m_wndMyDockablePane.Create(_T("Weaves & Color"), this, CRect(0, 0, 200, 200), TRUE,          ID_VIEW_MYDOCKABLEPANE, WS_CHILD | WS_VISIBLE | CBRS_TOP))
    {
        TRACE0("Failed to create dockable pane\n");
        return -1; // fail to create
    }   

    m_wndMyDockablePane.EnableDocking(CBRS_ALIGN_RIGHT | CBRS_ALIGN_LEFT);

    DockPane(&m_wndMyDockablePane);

    //this in my ColorDockable.cpp
    int ColorDockable::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        TRACE("ColorDockable::OnCreate called\n");

        if (CDockablePane::OnCreate(lpCreateStruct) == -1)
            return -1;

        if(!m_wndDialog.Create(IDD_DOC_COLOR_DLG, this));
        {
            TRACE("Failed to create dialog\n");
            return 0; // Fail to create
        }
        bool check = m_wndDialog.ShowWindow(SW_SHOWNORMAL);
        m_wndDialog.SetWindowPos(NULL, 0, 0, lpCreateStruct->cx, lpCreateStruct->cy, SWP_NOZORDER |    SWP_SHOWWINDOW);
        //ShowDockableDialog();
        return 0;
    }

//but its not created TRACE("Failed to create dialog\n");

Solution

  • The CDialog::Create() method creates a modeless dialog-box, which is not what you are after. Instead, check the CPaneDialog and CDialogBar classes, which are dialog-resource-based clasees, behaving as dockable pane and toolbar respectively - the latter is docked as well.

    Create a few test-projects, trying different settings for the Project style Option, at least the "Visual Studio" one, to check their look-and-fell, and decide which is best for you. Then you can copy parts of the wizard-generated code to your project, OR if the project is new create it again, with the desired options.

    You can also take a look in the CTRLBARS MFC Sample.