I had the same problem. It seems that WS_EX_DLGMODALFRAME only deletes the icon when there is no icon associated with it in the Win32 window of the Win32 window. 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 before resetting its icon when we use 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);
Edit: Oh, and it looks like this only works when the application starts outside of Visual Studio.
Zach johnson
source share