Occasionally, somebody wants to create a window without a Close button.
The only way to get rid of the Close button is not to have a System menu at all: Remove the WS_ style from the window. But that also gets rid of the Minimize and Maximize buttons, so it’s kind of drastic.
If you want a System menu, or if you want Minimize and Maximize buttons, you can at least disable the Close button by disabling the SC_CLOSE menu item.
HMENU menu = GetSystemMenu(hwnd, FALSE); EnableMenuItem(menu, SC_CLOSE, MF_DISABLED);
Of course, you could use the nuclear option and implement your own custom title bar. Then you can do whatever you want. But most people are probably not willing to take things to such an extreme.
But really, try not to hide or disable the Close the button at all. End users don’t like it. It makes them feel trapped.
I am very much surprised that GetSystemMenu followed by RemoveMenu doesn't remove it.
I've had a case or two for this awhile back in .NET where an uninterruptible server operation was running; and opted for a window that had no menu nor title bar. It would have been nice to allow the user to minimize the application during that time. Oh well.
Server operation would tend to take about two minutes; transaction handling was normal but cancelling the transaction from the client side was not possible by any means due to a fundamental deficiency of the Windows API itself involving pipes to...
You could handle WM_NCCALCSIZE and extend the client area into the non-client area. That way you can let DWM just draw the caption buttons on the right like normal but the left part (icon, title) stays empty and you only need to draw the window caption text yourself in the right location. That seems to me to be the easiest way to get rid of the caption icon but leaving the rest in place.
You should know that the system menu is tied to the caption icon, so if you still want the system menu to work, you need to...
Is there a way to create a window without a titlebar icon? As far as I know, apart from fully customizing the titlebar, there is no way to hide the icon without also hiding the title and the system menu. I was writing a small tool earlier and didn’t plan to design an icon for it, so it could only display the default icon, but it was meaningless.
well then Raymond, I shall trap the end users in my application
“You can use task manager ya know”
“Dammit.”