954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Remove window icon in WPF

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.

strmstn
Junior Poster
100 posts since Mar 2010
Reputation Points: 37
Solved Threads: 10
 

If you have an icon editor, why not create a completely transparant icon?

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

I would prefer not to, as that would leave an empty space.

strmstn
Junior Poster
100 posts since Mar 2010
Reputation Points: 37
Solved Threads: 10
 

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...

nmaillet
Posting Whiz in Training
236 posts since Aug 2008
Reputation Points: 69
Solved Threads: 53
 

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.

strmstn
Junior Poster
100 posts since Mar 2010
Reputation Points: 37
Solved Threads: 10
 

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

k.d.m
Light Poster
35 posts since May 2009
Reputation Points: 11
Solved Threads: 8
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: