Search code examples
wpfwindowicons

Hide the icon from a WPF window


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 icon disappears and does not take any empty space (i. e. no transparent icon)
  • The window title starts directly at the left edge of the window
  • The close button in the upper right corner is still there and works
  • Minimise/maximise buttons are still there if enabled (optional, didn't test this)
  • No custom-drawing of the entire window frame
  • Works on Windows 7 with Aero Glass enabled (Windows 8 anybody?)
  • Works on 32 and 64 bit Windows (x86 and x64 build)
  • Works with WPF .NET 4.0
  • Works when not in a debugger like Visual Studio (would be nice if it also works in the debugger)
  • Should also work on Windows XP (optional)

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?


Solution

  • 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);
    

    (s.a. https://connect.microsoft.com/VisualStudio/feedback/details/745230/wpf-window-cannot-be-displayed-without-titlebar-icon)