Remove close button from floating toolbar

The article ‘Remove system menu from floating toolbar’ by Sushil Saxena shows one way
of removing the close button from a toolbar. However, it is not the neatest of solutions
to the problem.

This is my solution: It does rely on a little dodge to get a runtime class for an
internal MFC class, but apart from that…

First, add some code somewhere, proabably in the cpp file, to get at that class.

// bodge class so we can get at the runtime class for this docked window
// helper class (not defined in any MFC header file)
class CMiniDockFrameWnd

Secondly, in the OnSize handler (called every time bar is floated or docked, but
not so often as a click) add

	// remove the close button on the parent
	CWnd *pParent = GetParent();
	if(pParent) pParent = pParent->GetParent();
	if(pParent != NULL && pParent->GetRuntimeClass() == RUNTIME_CLASS(CMiniDockFrameWnd)
		&& pParent->GetStyle() & WS_SYSMENU)
		pParent->ModifyStyle(WS_SYSMENU, 0, 0);

And your toolbar no longer has a close button.

More by Author

Must Read