dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: CDockablePane and CanBeClosed()

  1. #1
    Join Date
    Jan 2009
    Posts
    241

    CDockablePane and CanBeClosed()

    Hi all of you.

    From some time I am struggling to hide close button from an panel (CDockablePane), in an MFC application. Here is details: I have an MDI app, and in CChildFrame I inserted 2 panels:
    Code:
    class CChildFrame : public CMDIChildWndEx
    {
    	DECLARE_DYNCREATE(CChildFrame)
    public:
    	CChildFrame();
    
    protected:
    	CFilterWnd m_wndFilter;
    	CPropertiesWnd m_wndProperties;
    ...
    Code:
    int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    	if (CMDIChildWndEx::OnCreate(lpCreateStruct) == -1)
    		return -1;
    
    	// enable Visual Studio 2005 style docking window behavior
    	CDockingManager::SetDockingMode(DT_SMART);
    	// enable Visual Studio 2005 style docking window auto-hide behavior
    	EnableAutoHidePanes(CBRS_ALIGN_ANY);
    
    	CMDIChildWndEx::m_bEnableFloatingBars = TRUE;
    
    	// Create properties window
    	CString strPropertiesWnd;
    	BOOL bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);
    	ASSERT(bNameValid);
    	if(! m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, 
    		WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI, 
    		AFX_CBRS_REGULAR_TABS, AFX_NON_CLOSE_DOCKING_PANE_STYLE))
    	{
    		TRACE(_T("Failed to create Properties window\n"));
    		return FALSE; // failed to create
    	}
    	if(! m_wndFilter.Create(_T("Filter"), this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_FILTER, 
    		WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI, 
    		AFX_CBRS_REGULAR_TABS, AFX_NON_CLOSE_DOCKING_PANE_STYLE))
    	{
    		TRACE(_T("Failed to create Filter window\n"));
    		return FALSE; // failed to create
    	}
    
    	SetDockingWindowIcons(theApp.m_bHiColorIcons);
    
    	AddPane(&m_wndFilter);
    	AddPane(&m_wndProperties);
    	m_wndFilter.EnableDocking(CBRS_ALIGN_ANY);
    	m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);
    	DockPane(&m_wndFilter);
    	CDockablePane* pTabbedBar = NULL;
    	m_wndProperties.AttachToTabWnd(&m_wndFilter, DM_SHOW, TRUE, &pTabbedBar);
    	EnableAutoHidePanes(CBRS_ALIGN_ANY);
    
    	m_dockManager.LoadState(theApp.GetRegSectionPath(_T("ChildFrame")));
    	m_dockManager.SetDockState();
    
    	return 0;
    }
    so good so far ... I intend to remove the close button from panel, and I did it by:
    Code:
    virtual BOOL CanBeClosed() const {return FALSE;}
    in the panel header ... and the trick is working, when they are separate:
    https://imgur.com/8fL9iV2
    but when they are tabbed, the close button are still visible:
    https://imgur.com/ULMWMA9

    What I have done ? I have derived CDockablePane, and put there:
    Code:
    CTabbedPane* CNonClosableDockablePane::CreateTabbedPane()
    {
    	CTabbedPane* pTabbedPane = CDockablePane::CreateTabbedPane();
    	ASSERT_VALID(pTabbedPane);
    	// remove AFX_CBRS_CLOSE flag;
    	pTabbedPane->SetControlBarStyle(AFX_NON_CLOSE_DOCKING_PANE_STYLE);
    	return pTabbedPane;
    }
    
    BOOL CNonClosableDockablePane::PreTranslateMessage(MSG* pMsg) 
    {
    	// TODO: Add your specialized code here and/or call the base class
    
    	if(WM_SYSKEYDOWN == pMsg->message && VK_F4 == pMsg->wParam)
    		return TRUE;
    
    	return CDockablePane::PreTranslateMessage(pMsg);
    }
    and I write:
    Code:
    	m_dockManager.LoadState(theApp.GetRegSectionPath(_T("ChildFrame")));
    	m_dockManager.SetDockState();
    
    	if(NULL != pTabbedBar)	// remove AFX_CBRS_CLOSE flag
    		pTabbedBar->SetControlBarStyle(AFX_NON_CLOSE_DOCKING_PANE_STYLE);    // <--- An unhandled exception was encountered during a user callback.
    but I have a crash (see the comment above). Ok, then I have tried to remove the close style in another method, called after initialization:
    Code:
    	AddPane(&m_wndFilter);
    	AddPane(&m_wndProperties);
    	m_wndFilter.EnableDocking(CBRS_ALIGN_ANY);
    	m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);
    	DockPane(&m_wndFilter);
    	CDockablePane* pTabbedBar = NULL;
    	m_wndProperties.AttachToTabWnd(&m_wndFilter, DM_SHOW, TRUE, &pTabbedBar);
    	EnableAutoHidePanes(CBRS_ALIGN_ANY);
    
    	m_dockManager.LoadState(theApp.GetRegSectionPath(_T("ChildFrame")));
    	m_dockManager.SetDockState();
    
    	PostMessage(WMU_POSTINIT);
    and
    Code:
    LRESULT CChildFrame::OnPostInit(WPARAM wParam, LPARAM lParam)
    {
    	CDockablePane* pTabbedBar = (CDockablePane*)m_wndFilter.GetParentTabbedPane();
    	if(NULL != pTabbedBar)	// remove AFX_CBRS_CLOSE flag
    	{
    		pTabbedBar->SetControlBarStyle(AFX_NON_CLOSE_DOCKING_PANE_STYLE);
    		pTabbedBar->RecalcLayout();
    	}
    
    	return 1;
    }
    and I haven't any crash, but the close button are removed only after I changed the panels tab ... I guess that some redrawing are happen there, but I don't know how ... I even attach the sample project ... can you give me a little help ?

    Kind regards,
    Attached Files Attached Files

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,229

    Re: CDockablePane and CanBeClosed()

    Quote Originally Posted by mesajflaviu View Post
    ... Ok, then I have tried to remove the close style in another method, called after initialization:
    Code:
    	AddPane(&m_wndFilter);
    	AddPane(&m_wndProperties);
    	m_wndFilter.EnableDocking(CBRS_ALIGN_ANY);
    	m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);
    	DockPane(&m_wndFilter);
    	CDockablePane* pTabbedBar = NULL;
    	m_wndProperties.AttachToTabWnd(&m_wndFilter, DM_SHOW, TRUE, &pTabbedBar);
    	EnableAutoHidePanes(CBRS_ALIGN_ANY);
    
    	m_dockManager.LoadState(theApp.GetRegSectionPath(_T("ChildFrame")));
    	m_dockManager.SetDockState();
    
    	PostMessage(WMU_POSTINIT);
    and
    Code:
    LRESULT CChildFrame::OnPostInit(WPARAM wParam, LPARAM lParam)
    {
    	CDockablePane* pTabbedBar = (CDockablePane*)m_wndFilter.GetParentTabbedPane();
    	if(NULL != pTabbedBar)	// remove AFX_CBRS_CLOSE flag
    	{
    		pTabbedBar->SetControlBarStyle(AFX_NON_CLOSE_DOCKING_PANE_STYLE);
    		pTabbedBar->RecalcLayout();
    	}
    
    	return 1;
    }
    and I haven't any crash, but the close button are removed only after I changed the panels tab ... I guess that some redrawing are happen there, but I don't know how ... I even attach the sample project ... can you give me a little help ?

    Kind regards,
    Note that highlighted code is NEVER called!
    BTW, didn't you debug your code?
    Victor Nijegorodov

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,229

    Re: CDockablePane and CanBeClosed()

    Could this bug report be helpful?
    Victor Nijegorodov

  4. #4
    Join Date
    Jan 2009
    Posts
    241

    Re: CDockablePane and CanBeClosed()

    Quote Originally Posted by VictorN View Post
    Note that highlighted code is NEVER called!
    BTW, didn't you debug your code?
    Yes, I have checked if the code are going on there, and of course are called that piece of code ! No doubt ! You can verify this on my sample project.
    Last edited by mesajflaviu; January 9th, 2018 at 02:54 AM.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,229

    Re: CDockablePane and CanBeClosed()

    Quote Originally Posted by mesajflaviu View Post
    Yes, I have checked if the code are going on there, and of course are called that piece of code ! No doubt ! You can verify this on my sample project.
    Well, I verified it with your sample project with VS2015. I added some TRACE macros:
    Code:
    LRESULT CChildFrame::OnPostInit(WPARAM wParam, LPARAM lParam)
    {
    	TRACE("'CChildFrame::OnPostInit' enter into handler\n");
    	CDockablePane* pTabbedBar = (CDockablePane*)m_wndFilter.GetParentTabbedPane();
    	if(NULL != pTabbedBar)	// remove AFX_CBRS_CLOSE flag
    	{
    		TRACE("'CChildFrame::OnPostInit': calling the 'SetControlBarStyle(AFX_NON_CLOSE_DOCKING_PANE_STYLE);'\n");
    		pTabbedBar->SetControlBarStyle(AFX_NON_CLOSE_DOCKING_PANE_STYLE);
    		pTabbedBar->RecalcLayout();
    	}
    
    	TRACE("'CChildFrame::OnPostInit' return from handler\n");
    	return 1;
    }
    then ran it with debugger and got the following output>
    Code:
    ...\model\childfrm.cpp(161) : atlTraceGeneral - 'CChildFrame::OnPostInit' enter into handler
    ...\model\childfrm.cpp(170) : atlTraceGeneral - 'CChildFrame::OnPostInit' return from handler
    So it looks like the pTabbedBar->SetControlBarStyle(...) is NOT called. It is because m_wndFilter.GetParentTabbedPane() returns NULL.
    Victor Nijegorodov

  6. #6
    Join Date
    Jan 2009
    Posts
    241

    Re: CDockablePane and CanBeClosed()

    Ok, I have tested me too (VS2008):
    Code:
    LRESULT CChildFrame::OnPostInit(WPARAM wParam, LPARAM lParam)
    {
    	TRACE("=======Enter postinit\n");
    	CDockablePane* pTabbedBar = (CDockablePane*)m_wndFilter.GetParentTabbedPane();
    	if(NULL != pTabbedBar)	// remove AFX_CBRS_CLOSE flag
    	{
    		TRACE("=======Inside tabbedbar postinit\n");
    		pTabbedBar->SetControlBarStyle(AFX_NON_CLOSE_DOCKING_PANE_STYLE);
    		pTabbedBar->RecalcLayout();
    	}
    TRACE("=======Out postinit\n");
    	return 1;
    }
    and the trace is:
    Code:
    =======Enter postinit
    =======Inside tabbedbar postinit
    =======Out postinit
    another prove is that if I change panel tab in child frame, the close button will disappear ... if your code doesn't go by there, and you will change the panel tab, you will still have the close button of panels .... am I right ?

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,229

    Re: CDockablePane and CanBeClosed()

    1. I can't test it with VS2008 since I don't have it.
    2. In my test I saw the close buttons only after the very first start. All the same starts show your panels auto-hidden; then after slicking with mouse they are shown without the close button.
    Victor Nijegorodov

  8. #8
    Join Date
    Jan 2009
    Posts
    241

    Re: CDockablePane and CanBeClosed()

    "then after slicking with mouse they are shown without the close button" ... I am thinking that if I force redrawn that area, I will solve this issue ...

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,229

    Re: CDockablePane and CanBeClosed()

    Hi!
    I've just tested your sample project once more (cleaning the registry before starting it) and it works good enough: no close button for either Properties or Filters panes!
    Name:  Model.jpg
Views: 108
Size:  61.7 KB
    Victor Nijegorodov

  10. #10
    Join Date
    Jan 2009
    Posts
    241

    Re: CDockablePane and CanBeClosed()

    Quote Originally Posted by VictorN View Post
    Hi!
    I've just tested your sample project once more (cleaning the registry before starting it) and it works good enough: no close button for either Properties or Filters panes!
    Name:  Model.jpg
Views: 108
Size:  61.7 KB
    Very good observation !! Thank you ! Now I am thinking of an solution to start the app as didn't save the registry entry ...

  11. #11
    Join Date
    Jan 2009
    Posts
    241

    Re: CDockablePane and CanBeClosed()

    Quote Originally Posted by VictorN View Post
    Hi!
    I've just tested your sample project once more (cleaning the registry before starting it) and it works good enough: no close button for either Properties or Filters panes!
    Name:  Model.jpg
Views: 108
Size:  61.7 KB
    The good part is that now I can put the code in CChild::OnCreate(...) method (there is no need to do this job in an PostMessage):
    Code:
    	m_dockManager.LoadState(theApp.GetRegSectionPath(_T("ChildFrame")));
    	m_dockManager.SetDockState();
    
    	pTabbedBar->SetControlBarStyle(AFX_NON_CLOSE_DOCKING_PANE_STYLE);
    //	PostMessage(WMU_POSTINIT);
    and it goes well ... but second time, when I start the child, it crashes there (see the first post). ... strange ...
    Last edited by mesajflaviu; January 10th, 2018 at 02:15 AM.

  12. #12
    Join Date
    Jan 2009
    Posts
    241

    Re: CDockablePane and CanBeClosed()

    The issue is that I must keep the panels state and position, I cannot give up this feature ...

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,229

    Re: CDockablePane and CanBeClosed()

    Quote Originally Posted by mesajflaviu View Post
    ... but second time, when I start the child, it crashes there (see the first post). ... strange ...
    What is te exact reason of crash? And what kind of crash?
    Victor Nijegorodov

  14. #14
    Join Date
    Jan 2009
    Posts
    241

    Re: CDockablePane and CanBeClosed()

    Quote Originally Posted by VictorN View Post
    What is te exact reason of crash? And what kind of crash?
    Here is the crashes images:
    Name:  Capture.jpg
Views: 90
Size:  12.9 KB
    and
    Name:  Untitled.jpg
Views: 93
Size:  36.8 KB

    I think there is an conflict between saving/restoring panel, and removing close button ... but I don't know how to solve it ...
    Last edited by mesajflaviu; January 12th, 2018 at 01:39 AM.

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,229

    Re: CDockablePane and CanBeClosed()

    Could you copy/paste the exact error/exception message together with the additional info rather than post the links to some "unknown" sites?
    Victor Nijegorodov

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)