Integrate CMDITabBar into MDI MFC app

Flaviu_ 1,031 Reputation points
2025-07-10T10:45:15.25+00:00

I would like to use CMDITabBar (from WinMerge) into a MFC MDI test application.

Here is the test app: https://1drv.ms/u/c/dedcb6ef190b8fd4/ESppBUOCT-hJog-OyL43QXsBooSUM0liWkY9PHAeQo1FBw?e=BeSIzC

The code for integration (CMainFrame header):

protected:  // control bar embedded members
	CMFCMenuBar     m_wndMenuBar;
	CMFCStatusBar   m_wndStatusBar;
	CMDITabBar		m_wndTabBar; // <---

In implementation file:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!m_wndTabBar.Create(this))
	{
		TRACE(_T("Failed to create tab bar\n"));
		return -1;      // fail to create
	}
	m_wndTabBar.SetAutoMaxWidth(false);
....

But the tab control does not show up. I am thinking that is because the m_wndTabBar should be docked, which I also tried:

	// TODO: Delete these five lines if you don't want the toolbar and menubar to be dockable
	EnableDocking(CBRS_ALIGN_ANY);
	m_wndTabBar.EnableDocking(CBRS_ALIGN_ANY);
	m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndTabBar, AFX_IDW_DOCKBAR_TOP);

then, I got:

File: D:\a\_work\1\s\src\vctools\VC7Libs\Ship\ATLMFC\Src\MFC\winfrm2.cpp
Line: 92
				ASSERT(pDockBar != NULL);
				// assert fails when initial CBRS_ of bar does not
				// match available docking sites, as set by EnableDocking()

It is possible to use this CMDITabBar into a simple MDI MFC app? Can you help here?

P.S.

Here is the defintion of CMDITabs:

class CMDITabBar : public CControlBar
{
	DECLARE_DYNAMIC(CMDITabBar)
private:
	bool m_bOnTitleBar;
	CMyTabCtrl m_tabCtrl;
	CFont m_font;
	CTitleBarHelper m_titleBar;
public:
	CMDITabBar()
		: m_bOnTitleBar(true)
	{}
	virtual ~CMDITabBar() {}
	BOOL Update(bool bOnTitleBar, bool bMaxmized);
	void UpdateActive(bool bActive);
	BOOL Create(CMDIFrameWnd* pParentWnd);
	void UpdateTabs() { m_tabCtrl.UpdateTabs(); }
	bool GetAutoMaxWidth() const { return m_tabCtrl.GetAutoMaxWidth(); }
	void SetAutoMaxWidth(bool bAutoMaxWidth) { m_tabCtrl.SetAutoMaxWidth(bAutoMaxWidth); }
	int GetItemCount() const { return m_tabCtrl.GetItemCount(); }
	virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler) {}
	virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
protected:
	//{{AFX_MSG(CMDITabBar)
	afx_msg LRESULT OnNcHitTest(CPoint point);
	afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point);
	afx_msg void OnNcMouseLeave();
	afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
	afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
	afx_msg void OnNcLButtonUp(UINT nHitTest, CPoint point);
	afx_msg void OnNcRButtonDown(UINT nHitTest, CPoint point);
	afx_msg void OnNcRButtonUp(UINT nHitTest, CPoint point);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnPaint();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
};
Developer technologies | C++
{count} votes

Accepted answer
  1. Varsha Dundigalla(INFOSYS LIMITED) 155 Reputation points Microsoft External Staff
    2025-07-11T10:25:40.5466667+00:00

    Thank you for reaching out. Please find the steps below.
    Here’s a simplified version of your integration steps for CMDITabBar in an MFC MDI app:

    • Declare the tab bar in MainFrm.h using CMDITabBar m_wndTabBar;.
    • Create it in OnCreate() without docking:
    if (!m_wndTabBar.Create(this)) return -1;
    m_wndTabBar.SetAutoMaxWidth(false);
    RecalcLayout();
    
    • Override RecalcLayout() to manually position the tab bar above the MDI client and resize the client area below it.
    • Update tabs on MDI events like activation, creation, destruction, and title changes using UpdateTabs().
    • Avoid docking to prevent assertion errors. Manual layout gives better control and avoids style mismatches.

    This method ensures the tab bar appears correctly and stays in sync with MDI child windows—just like in WinMerge.
    Let us know if the issue persists after following these steps. We’ll be happy to assist further if needed.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.