System menu fix for floating toolbar

Environment: ****** -->

Default system menu for standard MFC toolbar has maximize/minimize/restore ability. I didn't like the way the Maximized toolbar looked. Ben Summers and Sushil Saxena already submited some ways to fix MFC bars, however, I found another one:

MFC removes SC_SIZE from toolbar frame each time when it appears.

BOOL CMiniDockFrameWnd::Create(CWnd* pParent, DWORD dwBarStyle)
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	pSysMenu->DeleteMenu(SC_SIZE, MF_BYCOMMAND);

The solution is a class derived from CMiniDockFrame with his own Create(...)

BOOL CFixedMiniFrameWnd::Create(CWnd* pParent, DWORD dwBarStyle)
	// set m_bInRecalcLayout to avoid flashing during creation
	// RecalcLayout will be called once something is docked
	m_bInRecalcLayout = TRUE;


	if (dwBarStyle & CBRS_SIZE_DYNAMIC)
		dwStyle &= ~MFS_MOVEFRAME;

	DWORD dwExStyle = 0;
#ifdef _MAC
	if (dwBarStyle & CBRS_SIZE_DYNAMIC)

	if (!CMiniFrameWnd::CreateEx(dwExStyle,
		NULL, &afxChNil, dwStyle, rectDefault, pParent))
		m_bInRecalcLayout = FALSE;
		return FALSE;
	dwStyle = dwBarStyle & (CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT) ?
	dwStyle |= dwBarStyle & CBRS_FLOAT_MULTI;

	CMenu* pSysMenu = GetSystemMenu(FALSE);

	pSysMenu->DeleteMenu(SC_SIZE, MF_BYCOMMAND);

	CString str;
	if (str.LoadString(AFX_IDS_HIDE))
	// convert SC_RESTORE to ToggleDocking();
	if (str.LoadString(AFX_IDS_DOCK))

	// must initially create with parent frame as parent
	if (!m_wndDockBar.Create(pParent, WS_CHILD | WS_VISIBLE | dwStyle,
		m_bInRecalcLayout = FALSE;
		return FALSE;

	// set parent to CMiniDockFrameWnd
	m_bInRecalcLayout = FALSE;

	return TRUE;

Then I add code to handle SC_RESTORE. This is not necessary, but why not?

BEGIN_MESSAGE_MAP(CFixedMiniFrameWnd, CMiniDockFrameWnd)

// CFixedMiniFrameWnd message handlers

void CFixedMiniFrameWnd::OnSysCommand(UINT nID, LPARAM)
	switch (nID & 0xFFF0)
		case SC_RESTORE:
			OnNcLButtonDblClk( HTCAPTION, CPoint(0,0));

Of course, MainFrame must know our new class

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

	// Use our own class for miniframes
	m_pFloatingFrameClass = RUNTIME_CLASS(CFixedMiniFrameWnd);


Download demo project - 17KB

Download demo only - 8KB


  • "afxChNil" undeclared identifier in

    Posted by Legacy on 09/17/2002 12:00am

    Originally posted by: ghj1976 can not build in

    if (!CMiniFrameWnd::CreateEx(dwExStyle,
    NULL, &afxChNil, dwStyle, rectDefault, pParent))

    "afxChNil" undeclared identifier in

    • even i am having this problem

      Posted by nidhinidhi on 06/24/2008 06:02am

      even i am having this problem

  • Multiple Frame Wnd Problems

    Posted by Legacy on 11/03/1999 12:00am

    Originally posted by: Robert Pearmain

    I have read your article on Mini Frame Windows with great interest. I have used the bars on 2 different CFrameWnd's.

    The problem is, if I set focus between the 2 frame windows via the main title captions, all is fine. However, if I try to set the focus of a window by clicking on the MiniFrameWnd title caption, I get a First Chance exception error:

    CWnd::Default() line 250 + 29 bytes
    CWnd::OnNcLButtonDown(unsigned int 2, unsigned int 2) line 414 + 15 bytes
    CMiniFrameWnd::OnNcLButtonDown(unsigned int 2, CPoint {x=318 y=215}) line 418
    CMiniDockFrameWnd::OnNcLButtonDown(unsigned int 2, CPoint {x=318 y=215}) line 908
    CWnd::OnWndMsg(unsigned int 161, unsigned int 2, long 14090558, long * 0x0012fd5c) line 1954
    CWnd::WindowProc(unsigned int 161, unsigned int 2, long 14090558) line 1575 + 30 bytes
    AfxCallWndProc(CWnd * 0x0068f120 {CWnd hWnd=0xdddddddd}, HWND__ * 0x00b70984, unsigned int 161, unsigned int 2, long 14090558) line 217 + 26 bytes
    AfxWndProc(HWND__ * 0x00b70984, unsigned int 161, unsigned int 2, long 14090558) line 371
    AfxWndProcBase(HWND__ * 0x00b70984, unsigned int 161, unsigned int 2, long 14090558) line 203 + 21 bytes
    USER32! 77e71820()

    What do I need to do so that I can select another Frame Window in the same app by clicking a MiniFrameWnd in that Window?

  • VC6.0 made this article obsolete.

    Posted by Legacy on 11/03/1999 12:00am

    Originally posted by: Paul Bludov

    CMiniDockFrameWnd::Create() from VC6 does it in a right way. It seems to there was a bug in VC5 and VC4.
    By the way, this bug appears only with WinNT4.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Hurricane Sandy was one of the most destructive natural disasters that the United States has ever experienced. Read this success story to learn how Datto protected its partners and their customers with proactive business continuity planning, heroic employee efforts, and the right mix of technology and support. With storm surges over 12 feet, winds that exceeded 90 mph, and a diameter spanning more than 900 miles, Sandy resulted in power outages to approximately 7.5 million people, and caused an estimated $50 …

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds