Menu

CDocker and CDockContainer

Help
ioannis
2024-06-14
2024-06-17
  • ioannis

    ioannis - 2024-06-14

    Hi David,

    I am trying to change the docker caption (docked and undocked) and the dock container tab text dynamically from within the view after creation (ie. think of the DockContainer sample, CViewClasses view, to change the above texts, depending on the view selection)

    Inspecting CDockContainer::SetTabText() and CDockContainer::SetDockCaption(), these functions set the new value to a class member variable which is only used during the creation or possible during undock and redock, but are not applied instantly to an exisitng dock.

    Also looking at CDockContainer::GetContainerFromView and CDockContainer::GetContainerIndex should there be a break in the for loop once the result is found ?

    Is it possible to implement this or advise the preferable way to go about this...
    Thank you.

     
  • David

    David - 2024-06-16

    Hi ioannis,

    I've updated the CDockContainer code to support the dynamic updating of the dock container's tab text, tab icon and caption.

    You can download the latest snapshot from the Code section here on SourceForge.

    Best regards,
    David

     
  • ioannis

    ioannis - 2024-06-16

    Hi David,
    Thank you very much for the update and the quick response.

    With regards to the SetDockCaption() if the text contains an ampersand &, this is transalated to an underscore _ like the menus... I consider this is not the intended behavour here.

    With regards to the SetTabText, this works only when SetOwnerDraw(TRUE) otherwise the new text is not taken into account.

    With regards to theCDocker::CDockClient i had to expose GetDocker in order to get the docker
    CDocker* GetDocker() { return m_pDocker; }

    Finally from a view (which is not a ported CWnd) i use the following hackish way to access and call CDockContainer functions:

    CDocker::CDockClient* pDockClient = (CDocker::CDockClient*)(CWnd::GetCWndPtr(::GetParent(m_hWnd)));
    CDockContainer::CViewPage* pViewPage = (CDockContainer::CViewPage*)(CWnd::GetCWndPtr(pDockClient->GetDocker()->GetParent().GetHwnd()));
    CDockContainer* pContainer = pViewPage->GetContainer();
    
    if (pContainer) {
        pContainer->SetDockCaption(caption);
        pContainer->SetTabText(tabText);
        pContainer->UpdateTabs();
    }
    

    Alternatively, I tried something in the lines of the below to get the CDockConatainer.

    CWnd* pWnd = CWnd::GetCWndPtr(::GetParent(*this));
    while (pWnd) {
        if (pWnd->GetClassNameW() == _T("Win32++ TabPage"))
            break;
        pWnd = CWnd::GetCWndPtr(pWnd->GetParent().GetHwnd());
    }
    CDockContainer* pContainer = ((CDockContainer::CViewPage*)(pWnd))->GetContainer();
    

    So my question is, is there a proper way to find/access the first CDockContainer given a HWND handle.

    Thank you in advance.

     

    Last edit: ioannis 2024-06-16
  • David

    David - 2024-06-17

    Hi ioannis,

    The container stays with its docker even when dockers and containers are rearranged. A view also stays with its container.

    Assuming the docker has an ID you can do something like this:

    CDocker* pDocker = GetDockFromID(ID_DOCK_OUTPUT2);
    if (pDocker)
    {
        CDockContainer* pContainer = pDocker->GetContainer();
        pContainer->SetDockCaption(L"***New Caption Text***");
        pContainer->SetTabText(L"*** Tab Text ***");
        pContainer->SetTabIcon(IDI_CLASSVIEW);
    }
    

    Alternatively you could store the docker's pointer or the container's pointer when it is created.

    Best regards,
    David

     
  • David

    David - 2024-06-17

    Other options are as follows:

    // Assuming hView is the HWND of your non Win32++ view window ... 
    HWND hContainer = ::GetParent(::GetParent(hView));
    LRESULT result = ::SendMessage(hContainer, UWM_GETCDOCKCONTAINER, 0, 0);
    CDockContainer* pContainer = reinterpret_cast<CDockContainer*>(result);
    
    // or ...
    CDockContainer* pContainer = static_cast<CDockContainer*>
            (GetCWndPtr(::GetParent(::GetParent(hView))));
    
    assert (dynamic_cast<CDockContainer*>(pContainer));   // Verify in debug mode.
    pContainer->SetDockCaption(L"*** New caption text ***");
    

    Best regards,
    David

     

Log in to post a comment.