SFML community forums

Help => General => Topic started by: Anthony11 on July 16, 2015, 05:13:05 pm

Title: set icon?
Post by: Anthony11 on July 16, 2015, 05:13:05 pm
how can i set an icon of window to a .ico file?
Title: Re: set icon?
Post by: Jesper Juhl on July 16, 2015, 05:39:21 pm
As far as I know SFML does not support ICO files.
But you can use a PNG.
Title: Re: set icon?
Post by: Hapax on July 16, 2015, 06:15:32 pm
sf::Window::setIcon() (http://www.sfml-dev.org/documentation/2.3.1/classsf_1_1Window.php#a63af61e026fba08e3153fd013620bcc0) takes a pointer to an array of pixels (in a specific order). An sf::Image stores its data in an array of pixels (in that required order) and can return a pointer to them.
Therefore, any of sf::Image's file formats can be used to set the window's icon.
From sf::Image::loadFromFile() (http://www.sfml-dev.org/documentation/2.3.1/classsf_1_1Image.php#a9e4f2aa8e36d0cabde5ed5a4ef80290b):
Quote
The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic.
Title: Re: set icon?
Post by: Anthony11 on July 16, 2015, 07:07:28 pm
well then, is it possible to set it from resource then?
Title: Re: set icon?
Post by: Hapax on July 16, 2015, 07:34:59 pm
It depends on your definition of the word resource. If you mean a resource such as a file (you can use the method above) or an sf::Texture (you can use loadFromImage in combination with the above method). However, if you mean Windows' definition of resource (e.g. a script linking external resources), you'll be using Windows-specific code (becomes non-cross-platform).
If you are looking for to only Windows-specific, you should look at this (https://msdn.microsoft.com/en-us/library/windows/desktop/ms648045%28v=vs.85%29.aspx) or that (https://msdn.microsoft.com/en-us/library/windows/desktop/ms648072%28v=vs.85%29.aspx). SFML can give you the window's handle (HWND) using sf::Window::getSystemHandle() (http://www.sfml-dev.org/documentation/2.3.1/classsf_1_1Window.php#a26368e7162229f8637c34d80ab0f138e).
This (http://www.cplusplus.com/forum/general/28470/) may also be of help (still Windows-specific).
Title: Re: set icon?
Post by: Mario on July 16, 2015, 08:47:33 pm
You can also embed the pixel data using a const uint8[] right in your code, which is essentially like your resource, but cross-platform (although a bit tricky to update).