2
votes

I need to remove the system menu and the icon from the title bar of my MFC dialog while keeping the maximize, minimize and close buttons.

I have tried using SetIcon(NULL, TRUE), SetIcon(NULL,FALSE) hoping that this will remove the icon. However, this didn't work. The icon still show while a bit messy, I think the app just took the main frame icon and resized it.

Can anyone help me with this.. I'm using VC++ 2010 SP1

Thanks

2

2 Answers

8
votes

The titlebar icon can also be removed independently from the min/max/exit buttons, by using extended styles (tested only on dialogs, don't know how it behaves on windows).

Paste the following code into your dialog's OnInitDialog() method and it should work:

// Disable default titlebar icon 
int extendedStyle = GetWindowLong(m_hWnd, GWL_EXSTYLE);
SetWindowLong(m_hWnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);

// Update non-client area of the dialog, for the changes to take effect
SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);

I have also unsuccessfully tried the SetIcon() method and many other proposed solutions/hacks and besides the upper (i.e. extended styles) none has been worked.

EDIT:

I've just stumbled apon a much simpler equivalent to the upper code:

Just add DS_MODALFRAME to the dialog box styles, along with WS_CAPTION and WS_SYSMENU.

https://msdn.microsoft.com/en-us/library/windows/desktop/ff729172%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

1
votes

In the resource editor, edit the properties of your dialog: Set "System Menu" to false. This will remove the WS_SYSMENU windows style of your dialog.

EDIT: Oops! I just re-read your question and realized you want to keep min and max boxes. My solution won't do that. This is an unusual requirement.