Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Setting application icon  (Read 12649 times)

0 Members and 1 Guest are viewing this topic.

drpitch

  • Newbie
  • *
  • Posts: 18
    • View Profile
Setting application icon
« 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!

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Setting application icon
« Reply #1 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 ?
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Setting application icon
« Reply #2 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.
Laurent Gomila - SFML developer

drpitch

  • Newbie
  • *
  • Posts: 18
    • View Profile
Setting application icon
« Reply #3 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!

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Setting application icon
« Reply #4 on: July 08, 2009, 08:10:16 pm »
you're welcome  :wink:
SFML / OS X developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Setting application icon
« Reply #5 on: August 24, 2009, 11:33:45 pm »
but then the executable icon is a crappy looking window, isnt it?

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Setting application icon
« Reply #6 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.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Setting application icon
« Reply #7 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