I want to hide/remove the game’s taskbar icon without hiding the game window itself. Since Unity is not capable of this I have tried hiding the icon using WS_EX_TOOLWINDOW:
C# Hiding an application from the taskbar, but had no luck.
Here, it suggested that “-batchmode” can hide the taskbar icon, which is true but this command hides the window too.
Achieving this should be possible since here, using WS_EX_TOOLWINDOW someone was able to hide the icon so I am definitely doing something wrong. This is how my code looks like right now:
[DllImport("User32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("User32.dll")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private const int SW_HIDE = 0x00;
private const int SW_SHOW = 0x05;
private const int GWL_EXSTYLE = -0x14;
private const int WS_EX_TOOLWINDOW = 0x0080;
void Start()
{
IntPtr pMainWindow = Process.GetProcessesByName("Game")[0].MainWindowHandle;
ShowWindow(pMainWindow, SW_HIDE);
SetWindowLong(pMainWindow, GWL_EXSTYLE, GetWindowLong(pMainWindow, GWL_EXSTYLE) | ~WS_EX_TOOLWINDOW);
ShowWindow(pMainWindow, SW_SHOW);
}
Just to be clear, I’m talking about this taskbar icon: