Removing an icon from a WPF window when working outside of Visual Studio

I used the code in Removing the icon from the WPF window to remove the icon from the application window (using the response of the attached property), and this handled the pleasure when starting through Visual Studio 2010 . When the application starts normally, the icon still appears.

There is no icon in the window assigned to its Icon property, however, the application has an icon defined in its properties (Application> Resources> Icon), which is displayed as a window icon.

How can I resolve this difference in behavior so that the icon does not appear when the application is running outside of Visual Studio 2010?

+7
source share
3 answers

I dug up a little; there is a question https://stackoverflow.com/a/3186263/12332 which is regarding your problem. Oddly enough, this fix only works outside of Visual Studio.

Relevant parts of the answer ( Zach Johnson ):

It seems that WS_EX_DLGMODALFRAME deletes the icon only when the Win32 window in the Win32 window does not have an icon associated with it. WPF (conveniently) uses the application icon as the default icon for all windows without an explicitly set icon. Usually this does not cause any problems and eliminates the need to manually install the application icon in each window; however, this creates a problem for us when we try to remove the icon.

Since the problem is that WPF automatically sets the window icon for us, we can send WM_SETICON to the Win32 window to reset its icon when we apply WS_EX_DLGMODALFRAME .

 const int WM_SETICON = 0x0080; const int ICON_SMALL = 0; const int ICON_BIG = 1; [DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern IntPtr SendMessage( IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); 

Code to remove the icon:

 IntPtr hWnd = new WindowInteropHelper(window).Handle; int currentStyle = NativeMethods.GetWindowLongPtr(hWnd, GWL_EXSTYLE); SetWindowLongPtr( hWnd, GWL_EXSTYLE, currentStyle | WS_EX_DLGMODALFRAME); // reset the icon, both calls important SendMessage(hWnd, WM_SETICON, (IntPtr)ICON_SMALL, IntPtr.Zero); SendMessage(hWnd, WM_SETICON, (IntPtr)ICON_BIG, IntPtr.Zero); SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); 

It only works when the application starts outside of Visual Studio.

+2
source

Perhaps Shell integration library is an option for you? It contains this WindowChrome class to configure the non-client area, allowing you to leave the icon.

0
source

Perhaps this will help you Hide the window buttons , not just the window icon, but if you like (minimize, restore, and close).

0
source

All Articles