Hello, I have been struggling with this for hours now.

Is there any way to completely remove the icon that is displayed in the upper left corner of a window in WPF, without setting the window style to ToolWindow?

I have tried loading user32 and setting various WinAPI-styles with no success.
It worked with setting the style to WS_EX_DLGMODALFRAME until I attached an icon to the assembly itself.

Thank you.

The only thing I can think of:

[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x00080000;

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    IntPtr handle = new WindowInteropHelper(this).Handle;
    SetWindowLong(handle, GWL_STYLE, GetWindowLong(handle, GWL_STYLE) & ~WS_SYSMENU);
}

This will however, remove the minimize, maximize and close buttons as well. I don't know of any other way around it...

Thank you for the suggestion, but I need the close button atleast.

It is weird that this is so hard to accomplish with such a modern framework when it was so easy with only C and WinAPI.

Edited 5 Years Ago by strmstn: n/a

you can change the icon by right clicking the project node in solution explorer and the icon that shows is displayed in application tab.

This article has been dead for over six months. Start a new discussion instead.