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,
↧