Developing on Staxmanade

Console Icon Swapping – Just for fun…

I took the new logo for StatLight and created a/an .ico (by going to for use as a FavIcon and so I could fancy up a couple of the windows just for fun. What I ended up figuring out, was how to change the icon for a running console window.

It’s actually pretty easy… Here is the class I wrote and use.

internal class ConsoleIconSwapper : IDisposable
IntPtr consoleWindowHwnd;

private const int WM_SETICON = 0x80; // Api constant
private const int ICON_SMALL = 0; // Api constant

private static extern int SendMessage(IntPtr hwnd, int message, int wParam, IntPtr lParam);

private static extern IntPtr GetConsoleWindow();

public ConsoleIconSwapper()
consoleWindowHwnd = GetConsoleWindow();

public void ShowConsoleIcon(Icon icon)
SendMessage(consoleWindowHwnd, WM_SETICON, ICON_SMALL, icon.Handle);

public void ChangeIconback()
SendMessage(consoleWindowHwnd, WM_SETICON, ICON_SMALL, (IntPtr)0);

public void Dispose()

And here is how I use it.

using (var consoleIconSwapper = new ConsoleIconSwapper())
* Code Here


This is what it looks like when in use…




Amused by simple things :)


Thanks man!

It works fine.