Remove close button from floating toolbar | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 22, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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
{
public:
	DECLARE_DYNAMIC(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.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.