C# – Setting a different taskbar icon to the icon displayed in the titlebar (C#)

ciconswinforms

I have both dark and light versions of my application icon; the dark version works best on gray surfaces such as Windows XP taskbar, where the light version works best as an icon in the titlebar.

Is there a way I can set the icon in the taskbar to a different icon than the one used in my form in C# (P/Invoke is fine)?

Best Answer

Send the WM_SETICON message to your form with different icon handles for the ICON_SMALL and the ICON_BIG parameter:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);

private const uint WM_SETICON = 0x80u;
private const int ICON_SMALL = 0;
private const int ICON_BIG = 1;

public MyForm()
{
    InitializeComponent();

    SendMessage(this.Handle, WM_SETICON, ICON_SMALL, Properties.Resources.IconSmall.Handle);
    SendMessage(this.Handle, WM_SETICON, ICON_BIG, Properties.Resources.IconBig.Handle);
}
Related Topic