SFML community forums

Help => General => Topic started by: Assassinbeast on November 14, 2012, 11:22:27 pm

Title: How do i put icons at my application?
Post by: Assassinbeast on November 14, 2012, 11:22:27 pm
ive looked at

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Window.php#a63af61e026fba08e3153fd013620bcc0 (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Window.php#a63af61e026fba08e3153fd013620bcc0)

void sf::Window::setIcon, but i didn't really understand it because it only have 3 parameters which is width, height and pixels. But where should i load the big & small icons?

Thanks for all your support  ;D
Title: Re: How do i put icons at my application?
Post by: Laurent on November 14, 2012, 11:24:32 pm
There's only one icon, which is used for both big and small sizes.
Title: Re: How do i put icons at my application?
Post by: eXpl0it3r on November 14, 2012, 11:33:29 pm
Well if you use a sf::RenderWindow, then you should look at the documentation for the rendern window, where you'd see sf::RenderWindow::setIcon (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Window.php#a63af61e026fba08e3153fd013620bcc0).

Also keep in mind that this will only change the icon at runtime, but the application icon in for example the explorer won't change. You'd have to set this in your IDE. ;)
Title: Re: How do i put icons at my application?
Post by: Assassinbeast on November 15, 2012, 12:26:57 am
I have only the express version of visual studio, so i cant use resources.

Quote
Well if you use a sf::RenderWindow, then you should look at the documentation for the rendern window, where you'd see sf::RenderWindow::setIcon.

Yes, i use renderwindow. But where in the code should i write so my program knows where to load the icon, and what can i write in the 3rd parameter of sf::Window::SetIcon?
Title: Re: How do i put icons at my application?
Post by: eXpl0it3r on November 15, 2012, 12:48:49 am
I have only the express version of visual studio, so i cant use resources.
Yes you can! You simply have to write the .rc file on your own, without the resource editor. ;)

Yes, i use renderwindow. But where in the code should i write so my program knows where to load the icon, and what can i write in the 3rd parameter of sf::Window::SetIcon?
Load the image into a sf::Image, then pass its size (width & height) as the first two parameters and for the third one: image.getPixelsPtr().
Title: Re: How do i put icons at my application?
Post by: mateandmetal on November 15, 2012, 05:10:05 am
There is a tutorial on the SFML Wiki:

Tutorial: Create and Use SetIcon (https://github.com/SFML/SFML/wiki/Tutorial%3A-Create-and-Use-SetIcon)
Title: Re: How do i put icons at my application?
Post by: Assassinbeast on November 15, 2012, 01:00:54 pm
Quote
Load the image into a sf::Image, then pass its size (width & height) as the first two parameters and for the third one: image.getPixelsPtr().

#include <SFML/Graphics.hpp>

sf::Image myicon;

int main()
{
        myicon.loadFromFile("snake.ico");
        sf::RenderWindow mywindow(sf::VideoMode(800,600,32),"icon");
        sf::Event ev;
        mywindow.setIcon(32,32,myicon.getPixelsPtr());
        while(mywindow.isOpen())
        {
                while(mywindow.pollEvent(ev))
                {
                        if(ev.type == sf::Event::Closed)
                                mywindow.close();
                }
                mywindow.clear(sf::Color(0,200,0));
                mywindow.display();
        }
}

I get an error in the console window that says:

Failed to load image "snake.ico". Reason : Image not of any known type, or corrupt.

 :-\
Also.... how can i pass the width and height?
myicon.width or height doesn't exist.

There is a tutorial on the SFML Wiki:

Tutorial: Create and Use SetIcon (https://github.com/SFML/SFML/wiki/Tutorial%3A-Create-and-Use-SetIcon)


That tutorial is from 1.6, and in 2.0 theres no .width or .height  :-\
Title: Re: How do i put icons at my application?
Post by: Laurent on November 15, 2012, 01:10:56 pm
Quote
Failed to load image "snake.ico". Reason : Image not of any known type, or corrupt.
Read the error message (and then the doc).

Quote
Also.... how can i pass the width and height?
myicon.width or height doesn't exist.
Read the doc.
Title: Re: How do i put icons at my application?
Post by: Assassinbeast on November 15, 2012, 09:55:00 pm
There's only one icon, which is used for both big and small sizes.

I got it to work with this code

#include <SFML/Graphics.hpp>

sf::Image myicon;

int main()
{
        myicon.loadFromFile("snake.png");
        sf::RenderWindow mywindow(sf::VideoMode(800,600,32),"icon");
        sf::Event ev;
        mywindow.setIcon(32,32,myicon.getPixelsPtr());
        while(mywindow.isOpen())
        {
                while(mywindow.pollEvent(ev))
                {
                        if(ev.type == sf::Event::Closed)
                                mywindow.close();
                }
                mywindow.clear(sf::Color(0,200,0));
                mywindow.display();
        }
}

But the big icon on the taskbar isn't showing. Why is that?
Title: AW: Re: How do i put icons at my application?
Post by: eXpl0it3r on November 15, 2012, 11:27:02 pm
Also keep in mind that this will only change the icon at runtime, but the application icon in for example the explorer won't change. You'd have to set this in your IDE. ;)
... which includes the Win7 taskbar icon...
Title: Re: How do i put icons at my application?
Post by: Assassinbeast on November 15, 2012, 11:48:09 pm
Quote
... which includes the Win7 taskbar icon...

Sorry im being so reckless sometimes  :(
I really appreciate all your help man, thanks alot  :)