I was wondering if there is a simple way add and remove an Icon of a WPF Window at runtime. This is not duplicate question; please read it carefully. I need a way to hide the icon of a WPF Window while the program is running and the window is initialized. All of my searches route to this code sample (from Stack Overflow):
IntPtr hwnd = new WindowInteropHelper(window).Handle;
// Change the extended window style to not show a window icon
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);
// Update the window's non-client area to reflect the changes
SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
...which doesn't work. I have tried it extensively and can confirm that on 64-Bit Windows 10 version 1607 it does not work at all. Another code sample I get directed to is this one (also from Stack Overflow):
const int ICON_SMALL = 0;
const int ICON_BIG = 1;
IntPtr hWnd = new WindowInteropHelper(this).Handle;
int currentStyle = (int)GetWindowLong(hWnd, GWL_EXSTYLE);
SetWindowLong(hWnd, GWL_EXSTYLE, (uint)currentStyle | WS_EX_DLGMODALFRAME);
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);
...which doesn't work either. Both options are seen in various adaptations all over the site, but I can't seem to get any of them working, even outside of Visual Studio. Is there now some new way that only works with windows 10? It would seem that the part which is not working is the frame redraw. As far as I can tell, it doesn't redraw anything. Are there any other options? All help is appreciated.