Hello,
I am trying to change the icon of my wpf application mainwindow and the one shown in task bar at runtime using Icon property in Window class and some native win32 api's. When I set the new icon the one on the left corner of mainwindow changes but the running application task bar icon does not reflect the change until I pin the running application to task bar then unpin it. (The application that I am running is not pinned to task bar during start)
What I understood that somehow the task bar is not refreshing the icon immediately.
Below is what I have tried.
//IntPtr hwnd = new WindowInteropHelper(this).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); //var icon = new System.Drawing.Icon(@"Icon1.ICO"); //ShowInTaskbar = false; //SendMessage(hwnd, WM_SETICON, (IntPtr)1, icon.Handle); //SendMessage(hwnd, WM_SETICON, (IntPtr)0, icon.Handle); //ShowInTaskbar = true; //SendMessage(GetWindow(hwnd, 4), WM_SETICON, (IntPtr)1, icon.Handle); //SendMessage(GetWindow(hwnd, 4), WM_SETICON, (IntPtr)0, icon.Handle); //TaskbarItemInfo.Overlay = new BitmapImage(new Uri(@"App.ico",UriKind.RelativeOrAbsolute)); Icon = new BitmapImage(new Uri("cool.ico", UriKind.RelativeOrAbsolute);
Any help or guidance would be much appreciated.
Thanks
Anshul