The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Load embedded icons to SDL_Surface
Alexey Petruchik
Guest

Is there any way to load embedded icons from rc file on windows to SDL_Surface? SDL_LoadBMP(iconname) seems to be not working for me.
Naith


Joined: 03 Jul 2014
Posts: 158
It depends on which icon you're talking about.

The different icons you can change is:

1. The icon that is seen when looking at the exe file in Windows Explorer (and other programs).
2. The icon that is seen in the task bar when the exe file is started.
3. The icon that is seen in the upper bar (to the left of the window title) when the application is started.

Icon 1 and 2 can easily be changed by choosing Add --> Resource --> Icon in Visual Studio. In there an icon of 16x16 size and an icon of 32x32 size can be created.
If you're using another IDE, you need to check how to add an icon file.
When the two icons has been created they should be seen in Windows Explorer and in the task bar as soon as the exe has been builded and executed.

Icon 3 is a bit harder to change and according to some pages there's ways to change it by using some Windows specific code, but I guess the icon change will only work on Windows then. Check these pages for more information:

http://forums.libsdl.org/viewtopic.php?t=8323&sid=4ad14ec89ec998528f309cf0fb7c7842
http://stackoverflow.com/questions/19311609/how-do-i-set-window-titlebar-icon-and-alt-tab-icon-in-sdl2-c-visual-studio

If you don't want to go through all that and write Windows-specific code, you can create the icon as a image file, convert it into a raw/binary file and then load it with SDL_LoadBMP_RW. The icon can then be changed by using SDL_SetWindowIcon and passing the surface that has been created with the function above.
I have never changed the icon in my applications / games but if I will do it, I will probably do it like that.
Load embedded icons to SDL_Surface
Alexey Petruchik
Guest

Ok, after some investigation it seems to be a missing functionality so i've created a pull request https://bugzilla.libsdl.org/show_bug.cgi?id=2841

On Fri, Jan 9, 2015 at 1:02 PM, Jeffrey Carpenter wrote:
Quote:
Hello,

I’m not familiar with RC files per se, but assuming you can figure out how to decode the file, you could do something like:


Use xxd (a command line utility) to dump the icon bitmap data into a C array that you can read back using SDL_RWops [1].


1. [url=https://wiki.libsdl.org/SDL_LoadBMP_RW?highlight=(%5CbCategoryAPI%5Cb)%7C(SDLFunctionTemplate)]https://wiki.libsdl.org/SDL_LoadBMP_RW?highlight=%28%5CbCategoryAPI%5Cb%29%7C%28SDLFunctionTemplate%29[/url]


(The SDL_Image extension also has IMG_LoadTyped_RW).


Err, instead of using xxd, you would substitute with the data stream from the RC file. I’m not sure how sane this is in practice, but just an idea in case nothing better comes along! :-)


Cheers,
Jeffrey Carpenter 










_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org