Hello Guys,
I’m trying to change the application icons on runtime based on my clients. I looked for days for a solution and only came up with using winapi and loading image but that works only for .ico and .bmp files but not for png.
What I ended up using is the code below.
It reads the icons at runtime from the disc. And it actually works “fine”. I’m not sure that is the most ideal solution to my problem so I thought I get advise from bigger and better programmers.
Edit: I just need it for windows standalone, Were using Unity pro
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", EntryPoint = "LoadImage", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType, int cxDesired, int cyDesired, uint fuLoad);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, int message, int wParam, IntPtr lParam);
private const int WM_SETICON = 0x80;
private const int ICON_SMALL = 0;
private const int ICON_BIG = 1;
void Awake()
{
if (Instance == null)
{
Instance = this;
}
}
void Start()
{
IntPtr smallIconHandle = LoadImage(IntPtr.Zero, @"C:\Icons\16x16.ico", 1, 16, 16, 0x00008010);
IntPtr bigIcontHandle = LoadImage(IntPtr.Zero, @"C:\Icons\32x32.ico", 1, 32, 32, 0x00008010);
IntPtr handle = GetForegroundWindow();
SendMessage(handle, WM_SETICON, ICON_SMALL, smallIconHandle);
SendMessage(handle, WM_SETICON, ICON_BIG, bigIcontHandle);
}
Every help would be appreciated,
Thanks!