I know that there are many questions about hiding or removing the icon from the upper left corner of a WPF window, the place where the system menu is. I've tried many of them but none works. Here are my requirements:
The available answers basically use the Windows API functions GetWindowLong
, SetWindowLong
and sometimes also SetWindowPos
to add the extended window style WS_EX_DLGMODALFRAME
and call SWP_FRAMECHANGED
. Sometimes, other styles are also set or unset.
Unfortunately, none of this works at all. I can either have no icon with no close button, or both are still there. But it's also noticeable that all of that content is from 2010 or eariler. It seems it's targeted at earlier .NET or Windows versions and fails since.
I've already compared the window styles of system dialogs (from Explorer) and my WPF windows with Microsoft Spy++ (included in Visual Studio). But I can try to set all flags the same, the icon won't go away. It's like black magic that overrules every other API function or physics.
Does anybody have a solution that still works today and in the indicated environment?
The above does not work, when creating a dialog window from a WPF application having an icon. However, when adding the following two lines, the icon correctly vanishes from the dialog window:
SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);