How to change application icon dynamically

Is there a way to change a Application icon dynamically? (Windows).
Normally, we drag a image to App icon screen and it is shown at the left-top corner when the application is launched.

After launching the Application, I need to change it with a selected different one.

Any idea?

Thanks in advance.

Here you go:

https://www.dropbox.com/s/h7u3gxnfg9efbj5/SetWindowIcon.xojo_binary_project?dl=1

just a proof of concept, you could improve this by storing the bitmap/icon after loading it rather than reading it from disk every time.

Look in the button action to see the filename as you might need to change this if it doesn’t exist on your disk:

SetWindowIcon("C:\\Program Files\\Xojo\\Xojo 2018r1\\Xojo Resources\\WindowsNotificationIcon32.png")

There is also a different method inside File->New->Examples->Platform-Specific->Windows->SetWindowIcon if this doesn’t work for you, but that version only works with icons that are already embedded inside exes or dlls.

Hope this helps.

Just corrected a memory leak by tidying up the created bitmap, the icon doesn’t need to be tidied up because its handled when the variable goes out of scope.

I also tried an alternate method using Picture.CopyOSHandle(Picture.HandleType.WindowsICON) however it was resulting in random crashes which I couldn’t find a solution for.