0

How to remove the icon from title bar in Windows Presentation Framework(.Net)?

I need just to remove the icon from the title bar only, not from any other place. When i switch my application from fullscreen to normal screen then the title bar icon is again appearing Can anyone suggest any durable solution?

1 Answers1

0

Try this

 public partial class MainWindow : Window
 {

    public MainWindow()
    {
        InitializeComponent();
    }

    [DllImport("user32.dll")]
    static extern int GetWindowLong(IntPtr hwnd, int index);

    [DllImport("user32.dll")]
    static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);

    [DllImport("user32.dll")]
    static extern bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int x, int y, int width, int height, uint flags);

    [DllImport("user32.dll")]
    static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam);

    const int GWL_EXSTYLE = -20;
    const int WS_EX_DLGMODALFRAME = 0x0001;
    const int SWP_NOSIZE = 0x0001;
    const int SWP_NOMOVE = 0x0002;
    const int SWP_NOZORDER = 0x0004;
    const int SWP_FRAMECHANGED = 0x0020;
    const uint WM_SETICON = 0x0080;

    protected override void OnSourceInitialized(EventArgs e)
    {
        base.OnSourceInitialized(e);
        IntPtr hwnd = new WindowInteropHelper(this).Handle;
        int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
        SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);
        SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

    }
}
Logan
  • 100
  • 1
  • 10
  • This is not working, when i switch my application from fullscreen to normal screen then the title bar icon is appearing again. – Adesh Kishore Dec 19 '18 at 06:50
  • This is working perfectly for me, can you share your code? – Logan Dec 19 '18 at 07:21
  • and one more thing in the task bar where the application icon is present when you hover it the icon is still coming. – Adesh Kishore Dec 19 '18 at 08:55
  • I don't think there are any tools that we can remove the icon from the taskbar. We can do only one thing, that is to use an empty icon. You can refer [this](https://www.codeproject.com/Questions/313586/Removing-titlebar-and-taskbar-icons) – Logan Dec 19 '18 at 12:00
  • I want to remove from the icon from title bar not the taskbar – Adesh Kishore Feb 14 '19 at 09:40