wxFrame icon

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.
Post Reply
pixsta
Knows some wx things
Knows some wx things
Posts: 34
Joined: Sat Dec 10, 2005 12:30 pm

wxFrame icon

Post 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,
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Did you call wxInitAllImageHandlers() in your app before setting your frame icon?
pixsta
Knows some wx things
Knows some wx things
Posts: 34
Joined: Sat Dec 10, 2005 12:30 pm

Post by pixsta »

no, I did not call it. But also when I call it, it does not work.
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

PNG isn't supportet by wxIcon, neither jpg etc.

Read the Manual ;)
pixsta
Knows some wx things
Knows some wx things
Posts: 34
Joined: Sat Dec 10, 2005 12:30 pm

Post by pixsta »

I also tried gif and ico files. both do not work.
Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Post 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));
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post 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.
Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post 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
emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

Post by emarti »

According to me, Using xpm file for icon is more easy.
- T U R K E Y ?
- I love this country!

WebSites:
http://mebt.sourceforge.net/
http://wxquran.sourceforge.net/
Post Reply