What could cause the wxIcon constructor to fail from a Windows resource file?

162 views
Skip to first unread message

ardi

unread,
Jul 5, 2012, 2:14:55 PM7/5/12
to wx-users
No matter how hard I tried, I cannot succeed to load resource icons in
MSW to set my wxFrame icon.

In order to discard possible causes, I took the wxWidgets "sample.ico"
file. I put a line like this in my rc file:

sample ICON "sample.ico"

And then, in my wxFrame constructor:

SetIcon(wxICON(sample));

This does nothing.

Then I try to debug the cause, so I use the wxIcon constructor
instead, and IsOK() returns false, so the problem isn't with
SetIcon(), but with getting the icon from the resource file...

What could be happening here? The "sample.ico" file works fine with
the wxWidgets samples, so that's not suspicious. The resource file
works fine otherwise (XP themes fine, Explorer icon fine, minimized
icon fine...).

I'm building with mingw (gcc 4.6.3). Must I take any special measures
in the link line?

Well... I tried everything and have no idea on what to look from
here...

TIA

ardi

Vadim Zeitlin

unread,
Jul 5, 2012, 3:00:01 PM7/5/12
to wx-u...@googlegroups.com
On Thu, 5 Jul 2012 11:14:55 -0700 (PDT) ardi wrote:

a> SetIcon(wxICON(sample));
a>
a> This does nothing.

Not even an error message? Because I'd expect it to give an error if you
don't link with the .res file. But if you obtain nothing at all, this is
strange.

a> I'm building with mingw (gcc 4.6.3). Must I take any special measures
a> in the link line?

You must compile the .rc file into .res and link with the latter. Do you?
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

ardi

unread,
Jul 5, 2012, 3:25:43 PM7/5/12
to wx-users


On 5 jul, 21:00, Vadim Zeitlin <va...@wxwidgets.org> wrote:
> On Thu, 5 Jul 2012 11:14:55 -0700 (PDT) ardi wrote:
>
> a> SetIcon(wxICON(sample));
> a>
> a> This does nothing.
>
>  Not even an error message? Because I'd expect it to give an error if you
> don't link with the .res file. But if you obtain nothing at all, this is
> strange.


No, no errors


>
> a> I'm building with mingw (gcc 4.6.3).  Must I take any special measures
> a> in the link line?
>
>  You must compile the .rc file into .res and link with the latter. Do you?


Please forgive my MSW ignorance (not my ecosystem :-( but I'm using
the windres from mingw to compile the '.rc' file as an '.o' file and I
link the later with the rest of the application object code. So I
don't link any '.res' file.

Thanks!

ardi

Vadim Zeitlin

unread,
Jul 5, 2012, 7:04:06 PM7/5/12
to wx-u...@googlegroups.com
On Thu, 5 Jul 2012 12:25:43 -0700 (PDT) ardi wrote:

a> > a> I'm building with mingw (gcc 4.6.3).  Must I take any special measures
a> > a> in the link line?
a> >
a> >  You must compile the .rc file into .res and link with the latter. Do you?
a>
a> Please forgive my MSW ignorance (not my ecosystem :-( but I'm using
a> the windres from mingw to compile the '.rc' file as an '.o' file and I
a> link the later with the rest of the application object code. So I
a> don't link any '.res' file.

Yes, you're right, sorry, I forgot about this difference between MSVC and
MinGW.

What about the size of your icon(s), are they different from the standard
ones by chance?

If not, I can only recommend the usual method, i.e. try to reproduce your
problem in the minimal sample. It does have makefile.gcc that you can use
to build it with MinGW, so maybe just trying your icon in it would be
already a good first step.

Regards,

Steve Barnes

unread,
Jul 6, 2012, 1:23:11 AM7/6/12
to wx-users
I know this might sound like stating the obvious but you have copied sample.icon to both your source directory AND your executable directory?

-----Original Message-----

From: ardi
Sent: 5 Jul 2012 18:14:57 GMT
To: wx-users
Subject: What could cause the wxIcon constructor to fail from a Windows resource file?

No matter how hard I tried, I cannot succeed to load resource icons in
MSW to set my wxFrame icon.

In order to discard possible causes, I took the wxWidgets "sample.ico"
file. I put a line like this in my rc file:

sample ICON "sample.ico"

And then, in my wxFrame constructor:

SetIcon(wxICON(sample));

This does nothing.

Then I try to debug the cause, so I use the wxIcon constructor
instead, and IsOK() returns false, so the problem isn't with
SetIcon(), but with getting the icon from the resource file...

What could be happening here? The "sample.ico" file works fine with
the wxWidgets samples, so that's not suspicious. The resource file
works fine otherwise (XP themes fine, Explorer icon fine, minimized
icon fine...).

I'm building with mingw (gcc 4.6.3). Must I take any special measures
in the link line?

Well... I tried everything and have no idea on what to look from
here...

TIA

ardi

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+u...@googlegroups.com
or visit http://groups.google.com/group/wx-users

ardi

unread,
Jul 6, 2012, 9:14:59 AM7/6/12
to wx-users


On Jul 6, 7:23 am, Steve Barnes <gadgetst...@live.co.uk> wrote:
> I know this might sound like stating the obvious  but you have copied sample.icon to both your source directory AND your executable directory?

I don't think it's needed on the executable directory, as the
"sample.ico" is embedded into the executable.

Anyway, I was told about a freeware tool called "resource hacker". I
used it with my executable, and all the icons are there. However, in
the section where their names should be, there's just quotation marks.
I'm beginning to suspect my mingw windres, so I believe the icons are
correctly set in my executable, but their names get somehow trashed.
Before you make any questions, yes, my ".rc" file is plain 7bit ASCII,
and the icon names are simple ones like 'aaaaaaaa' or 'sample'.

If anybody has run into a problem like this in the past, please tell.
Otherwise I'll investigate if it's a problem with my mingw windres.

Thanks again!

ardi

ardi

unread,
Jul 6, 2012, 1:34:55 PM7/6/12
to wx-u...@googlegroups.com


On Friday, July 6, 2012 3:14:59 PM UTC+2, ardi wrote:
[...] 
I'm beginning to suspect my mingw windres, so I believe the icons are 
correctly set in my executable, but their names get somehow trashed.

I can confirm I had a bug on my windres. I'm crosscompiling to windows from OSX, and I've just hit this bug:  http://sourceware.org/bugzilla/show_bug.cgi?id=13409

ardi

Reply all
Reply to author
Forward
0 new messages