Custom Icon problem when targeted Windows C++

I don’t know if it’s just me or not
no matter how I set Icon

the icon I set only shows on explorer and toolbar
It won’t show on window top left, no matter openFL default icon or custom icon
It just show the default Windows icon

Icon not showed in property windows
Icon showed in window is windows default Icon

I have tried different icon, different format, different size, different version of OpenFL
not a single one is working

1 Like

Hi!

We have a program that embeds a Windows ICO in the executable, so that it can use an icon properly. This appears to have stopped working at runtime in SDL2, I’ve just gone in and fixed this behavior on both Lime and on Lime legacy, now. The next development builds of Lime and OpenFL should support a proper window icon when targeting Windows, I apologize for the trouble, but it does work now :slight_smile:

Hi,
now something wrong with my icon :smile:

Here is how my icon should be:

Here is how it looks after last update:

But the icon in window title works ok! :wink:

It’s following two different paths in the tools, it’s strange that the ICO is not coming through correctly :confused:

The working PNG icon is using IconHelper.createIcon:

https://github.com/openfl/lime/blob/master/tools/helpers/IconHelper.hx#L28

The ICO which is not working properly is coming from IconHelper.createWindowsIcon, though it’s strange, because it seemed to work properly, the last I used it:

https://github.com/openfl/lime/blob/master/tools/helpers/IconHelper.hx#L139

If you have the ability to peak in on the tools, this is where it would occur, otherwise, perhaps I could try and look into it if I had your icon file(s). Thanks! :success:

I’m glad to see Icon is being fixed

however, I got problem,too
I’m using OpenFL default svg icon
this is what it looks like now

Got it, just committed a fix, should go out in the next Lime release, thank you :slight_smile:

Good to see fix incoming

however, there’s a last poblem
don’t know if i mess up something or not
I edited lime code like you did in github and use “lime rebuild tools windows” to see if it’s work
now I can see Icon in window, windows explorer, toolbar…
don’t know why, the Icon in property window is complete black

Did you also “git submodule update” and “lime rebuild windows -Dlegacy”?

updated and rebuilt windows legacy
It’s still a black box in property window
might have something to do with alpha channel?

I looked for several Ico file and I think I found something might be problem?
although most application use 32bit color as Icon, but they still keep 256 color format icon in ico file
is it possible to make IconHelper generate 256 color icon?

I’m having a problem with the icons being miscolored using many pngs or svg usually with a pink color. (Everything seems to work but the discoloration) :smile:

You can fix it by edit IconHelper.hx


run “lime rebuild tools” will fix it

the last problem I’m talking about is Icon’s color become black & white in property window
it’s more like it turned any color into black and only alpha channel (transparency) is working

1 Like

Thanks, I got that too but at random when I compile my game I really hope it gets fixed

Ah, I see the problem. The “Properties” window icon is different. The application icon (alt + tab plus the application window) should be fixed, the icon in Explorer should be working as well, but Properties is not working here.

I think we need to try and do a Windows embedded resource for the icon, “the proper way”, it allows the use of multiple icon resolutions all in the same application, I think this may be essential for “Properties” to work, I’m just having trouble finding how we would embed it

I tried manually edit 32x32 icon to 256 color and use ReplaceVistaIcon again
I think Lime also use it to embed icon?

then Tada~
no more black n white Icon in Property window

Through much pain and suffering, I have gotten proper icon support going on Windows.

Getting bitmap output to work properly carried a lot of nuances. Eventually, I decided to break it out into a new BMP.encode method in Lime, so this is now usable by other projects that would like to use bitmap format encoding as well :smile:

I ended up implementing three different forms of bitmaps, the standard RGB that only displays color and no alpha, also BITFIELD which does support alpha but (surprise surprise!) this format of bitmap is not support by the Windows icon format. There’s a severe lack of documentation out there :wink:

I also added a special ICO format for bitmap, which has a special AND mask – though I could not get that to work correctly. The AND mask we had before was broken, ultimately it was the cause of the black image. Most variations of AND masks I used either resulted in Windows automatically using it’s own estimation (which caused some bad artifacts on the Lime icon) or one that worked perfect, except for some vertical lines. Someone who is knowledgable might tweak the AND mask and find a way to get it to work. This would be most useful for old systems, like Windows XP, or even before, so this might not be an issue. Ultimately, I find that including a blank AND mask seemed to result in Windows respecting the alpha pixel values in the bitmap, and magically, it seems to work perfectly, or look perfect, even though I know it’s not quite kosher.

By the way, if anyone works on this, the Windows icon cache is a pain to clear. I use Windows 10, and it never worked for me. My trick was to rename my executable each time I published (such as “MyApplication.exe” and “_MyApplication.exe”) and not to delete so I was sure I had not used the name before. Crude, but eventually I got it :wink:

I’m very glad to see that the “ReplaceVistaIcon.exe” tool that we use to push in the icon is working correctly, once you have an icon file that’s truly proper. Oh, I also made the 256x256 icon a PNG instead of a bitmap, so that should save on the file size and make it the way Windows really expects.

I’m also happy to report that I found how I can control the resource ID of the embedded icon, as well as making the created SDL window respect and use the embedded icon. Now I am not using setIcon to set it at runtime, but instead it will respect the same ICO file that’s within the EXE. This is ideal, because no single icon PNG really matches all the icon sizes Windows asks for. Now Windows should be able to pull the exact size it wants, so your icon looks proper in all situations.

Lastly, “ReplaceVistaIcon.exe” failed before using Neko (it broke the executable), but I worked around it, so Neko as well as C++ have the icon.

It was quite the crusade, but I’m happy to report that we’ve all come out as the victors. This shouldn’t be something we need to change, so expect proper Windows icons from now on :success:

5 Likes

Here’s a screenshot:

:yey:

2 Likes

@singmajesty Thank you for the fix, now anything made with openfl/lime will look way more professional.

Edit:
don’t know why, I deleted entire bin folder and rebuild a debug verison again
now the icon in property window works fine now


hello
thanks for effort, but don’t know why it’s still a sad black box in property window
I have updated all library, deleted old compiled cpp file and rebuild entire project

it’s a default openfl SVG icon, I’m using Win7 64bit

There is another strange problem with icons generated from svg. The transparent parts are not totally transparent and have some opacity and a blue tint in my case.
The vector svg file did not change it is the same as before openfl upgrade.
But new generated icons have this problem, specifically when I build for android.