Page 1 of 1

wxFrame icon

Posted: Fri Mar 24, 2006 6:17 pm
by pixsta
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,

Posted: Fri Mar 24, 2006 6:24 pm
by benedicte
Did you call wxInitAllImageHandlers() in your app before setting your frame icon?

Posted: Fri Mar 24, 2006 6:32 pm
by pixsta
no, I did not call it. But also when I call it, it does not work.

Posted: Fri Mar 24, 2006 6:44 pm
by phlox81
PNG isn't supportet by wxIcon, neither jpg etc.

Read the Manual ;)

Posted: Fri Mar 24, 2006 6:58 pm
by pixsta
I also tried gif and ico files. both do not work.

Posted: Fri Mar 24, 2006 7:05 pm
by Ksmith22
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));

Posted: Fri Mar 24, 2006 7:44 pm
by benedicte
I use a .ico file referenced in a .rc file:

Code: Select all

FRAME_ICON             ICON                    "res\\app.ico"
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.

Posted: Fri Mar 24, 2006 7:58 pm
by Avi
benedicte wrote:I use a .ico file referenced in a .rc file:

Code: Select all

FRAME_ICON             ICON                    "res\\app.ico"
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

Posted: Fri Mar 24, 2006 11:40 pm
by emarti
According to me, Using xpm file for icon is more easy.