If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
pixsta
Knows some wx things
Posts: 34 Joined: Sat Dec 10, 2005 12:30 pm
Post
by pixsta » Fri Mar 24, 2006 6:17 pm
Hello!
I want to add a icon to my wxframe:
Code: Select all
wxIcon wxicon;
wxicon.LoadFile("icon.png",wxBITMAP_TYPE_PNG); // returns false everytime
myframe->SetIcon(wxicon);
The problem is, that "LoadFile" returns false. I also tried it with a gif. The size of the png is 32x32x24.
Thank you,
benedicte
wxWorld Domination!
Posts: 1409 Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France
Post
by benedicte » Fri Mar 24, 2006 6:24 pm
Did you call wxInitAllImageHandlers () in your app before setting your frame icon?
pixsta
Knows some wx things
Posts: 34 Joined: Sat Dec 10, 2005 12:30 pm
Post
by pixsta » Fri Mar 24, 2006 6:32 pm
no, I did not call it. But also when I call it, it does not work.
phlox81
wxWorld Domination!
Posts: 1387 Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:
Post
by phlox81 » Fri Mar 24, 2006 6:44 pm
PNG isn't supportet by wxIcon, neither jpg etc.
Read the Manual
pixsta
Knows some wx things
Posts: 34 Joined: Sat Dec 10, 2005 12:30 pm
Post
by pixsta » Fri Mar 24, 2006 6:58 pm
I also tried gif and ico files. both do not work.
Ksmith22
I live to help wx-kind
Posts: 199 Joined: Mon Nov 21, 2005 4:34 pm
Post
by Ksmith22 » Fri Mar 24, 2006 7:05 pm
I've had the same problem in the past. I believe I ended up being forced to use an XPM as that was the only format I could get to work. wxWidgets seems to have some real problems reguarding icons and especially reading stuff from Resource Files.
Here's the syntax I used for mine:
Code: Select all
#include "myicon.xpm" // at the top
// In the code
frame->SetIcon(wxIcon(myicon_xpm));
benedicte
wxWorld Domination!
Posts: 1409 Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France
Post
by benedicte » Fri Mar 24, 2006 7:44 pm
I use a .ico file referenced in a .rc file:
and in my main frame constructor:
Code: Select all
#ifdef __WXMSW__
wxIcon icon;
icon.LoadFile (wxT("FRAME_ICON"), wxBITMAP_TYPE_ICO_RESOURCE);
SetIcon(icon);
#endif
It works well.
Avi
Super wx Problem Solver
Posts: 398 Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel
Post
by Avi » Fri Mar 24, 2006 7:58 pm
benedicte wrote: I use a .ico file referenced in a .rc file:
and in my main frame constructor:
Code: Select all
#ifdef __WXMSW__
wxIcon icon;
icon.LoadFile (wxT("FRAME_ICON"), wxBITMAP_TYPE_ICO_RESOURCE);
SetIcon(icon);
#endif
It works well.
Instead of having the #ifdef... check what the docs say:
A macro, wxICON, is available which creates an icon using an XPM on the appropriate platform, or an icon resource on Windows.
wxIcon icon(wxICON(mondrian));
// Equivalent to:
#if defined(__WXGTK__) || defined(__WXMOTIF__)
wxIcon icon(mondrian_xpm);
#endif
#if defined(__WXMSW__)
wxIcon icon("mondrian");
#endif
emarti
Filthy Rich wx Solver
Posts: 210 Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:
Post
by emarti » Fri Mar 24, 2006 11:40 pm
According to me, Using xpm file for icon is more easy.