SFML community forums

Help => Graphics => Topic started by: drpitch on July 08, 2009, 03:23:40 pm

Title: Setting application icon
Post by: drpitch on July 08, 2009, 03:23:40 pm
Hi all,

I'd like to set an image icon for my application. I'm using C++ on Visual Studio 2008.

I've seen that there's a SetIcon method that receive a pointer to the buffer of the image, but I really don't know how to use it since I've got a HICON:
Code: [Select]

sf::RenderWindow m_window;
HICON hIcon = (HICON) LoadImage(instance, MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);

m_window.SetIcon(32, 32, ???);


Does anyone know how this can be done?

Thanks!
Title: Setting application icon
Post by: Hiura on July 08, 2009, 05:45:23 pm
It's easier with sf::Image ( and cross-platform  :wink: ) .

Code: [Select]
sf::Image icon;
icon.LoadFrom*(...); // File/Image/Pixel
my_window.SetIcon(icon.GetWidth(), icon.GetHeight(), icon.GetPixelsPtr());
simple, isn't it ?
Title: Setting application icon
Post by: Laurent on July 08, 2009, 05:52:12 pm
Quote
It's easier with sf::Image

I think he wants to load the icon from the executable ;)

There are more cross-platform techniques to achieve that, like converting your icon file to a C++ header, and then using LoadFromMemory functions family in SFML.

If you want to stick with Win32, I think you'll have to lock the resource, obtain a direct pointer on the pixels (maybe after a few conversions to HBITMAP or whatever) and release the resource. MSDN is your best friend.
Title: Setting application icon
Post by: drpitch on July 08, 2009, 07:16:49 pm
Well, I'd prefer to load the icon from the executable, but loading it from a file it's not a bad solution ;)

I've finally done what Hiura says, after converting the icon to a png file ;)

Thanks!
Title: Setting application icon
Post by: Hiura on July 08, 2009, 08:10:16 pm
you're welcome  :wink:
Title: Setting application icon
Post by: panithadrum on August 24, 2009, 11:33:45 pm
but then the executable icon is a crappy looking window, isnt it?
Title: Setting application icon
Post by: Imbue on August 25, 2009, 09:21:56 am
Quote from: "panithadrum"
but then the executable icon is a crappy looking window, isnt it?
That's an issue for your compiler.
Title: Setting application icon
Post by: panithadrum on August 25, 2009, 01:07:34 pm
Quote from: "Imbue"
Quote from: "panithadrum"
but then the executable icon is a crappy looking window, isnt it?
That's an issue for your compiler.


Belive me or not, you solved my problem :D
Thanks!

BTW, SFML is amazing