Real hard time with resource icons Topic is solved

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
fm
Knows some wx things
Knows some wx things
Posts: 27
Joined: Tue Nov 01, 2005 9:37 pm

Real hard time with resource icons

Post by fm » Tue Nov 08, 2005 8:44 pm

I'm having a real hard time trying to load a resource icon, it just doesn't work.
The resource works fine, as it shows the Icon on the explorer and on the taskbar, but when loading this way:

Code: Select all

wxIcon icon(wxICON(RinoIcon));
Just doesn't work.
Follows the entire resource file:
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// Portuguese (Brazil) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PTB)
#ifdef _WIN32
LANGUAGE LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
RinoIcon ICON DISCARDABLE "RinoIcon.ico"

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END

3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED

#endif // Portuguese (Brazil) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

Please someone help me here, I've been days trying to figure this out.

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Wed Nov 09, 2005 7:48 am

Are you trying to get an icon in the left corner of your window?
If so, it might be easier to also use an XPM file as resource files is a windows only thing. If you use an XPM file, you can easily set the icon.

Code: Select all

wxIcon icon(my_xpm_icon);
wxFrame::SetIcon(icon);
Plus that it's platform independent. So under linux this icon will also show.

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio » Wed Nov 09, 2005 8:23 am

The technique to have it transparent is the following (or at least that I use):

* Have both bitmap resources and xpm files for the images.
* The name of the win resource should be the character arrays name used in the xpm file, minus the _XPM suffix. I renamed the char arrays name to something like IDB_ICON_XPM, but changing the name written inside the .rc might be easier
* Include the xpm files on top of the source inside #ifndef __WXMSW__ (I have a separate preprocessor definition for this to optionally support using xpm's on windows)
* Construct them with wxICON(resource_name), e.g with the example above with wxICON(IDB_ICON). If you need a bitmap, then wxBITMAP(IDB_ICON) could be used. wxICON is a macro that evaluates it to wxIcon("IDB_ICON", wxBITMAP_TYPE_ICO_RESOURCE) on Windows, and wxIcon(IDB_ICON_xpm, wxBITMAP_TYPE_XPM) elsewhere.

Then you could probably just write

Code: Select all

wxFrame::SetIcon(wxICON(IDB_ICON));
Of course all this can also be approached differently.

My approach can be seen in action at
http://cvs.sourceforge.net/viewcvs.py/w ... &view=auto
for example.
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/

fm
Knows some wx things
Knows some wx things
Posts: 27
Joined: Tue Nov 01, 2005 9:37 pm

Post by fm » Wed Nov 09, 2005 11:30 am

The thing is, why is it not working with the windows resource? What is the problem, I'll try using the XPM file and such. But portability is not a big deal...

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Wed Nov 09, 2005 11:51 am

try changing RinoIcon ICON DISCARDABLE "RinoIcon.ico" to RinoIcon ICON "RinoIcon.ico" - i dont think DISCARDABLE sounds nice lol

xee
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sat Feb 19, 2005 9:26 pm

here's how to do it

Post by xee » Wed Nov 09, 2005 12:11 pm

first in the resource, you should have something like:

Code: Select all

ICONPRG ICON "App.ico"
your resources seem fine.

now, in the source code, you should have this line in the initialization function of the wxFrame:

Code: Select all

SetIcon(wxICON(ICONPRG));
that's how it's working for me.

fm
Knows some wx things
Knows some wx things
Posts: 27
Joined: Tue Nov 01, 2005 9:37 pm

Post by fm » Wed Nov 09, 2005 2:59 pm

It's not me who puts that DISCARDABLE, it's MSVC6 and I've got no clue how to get it out, hand editing simply won't work.
xee, I'm doing that exact way...

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Wed Nov 09, 2005 3:09 pm

why cant you hand edit? if you cant hand edit im sure theres a way somewhere...

if not make your own RC file?

fm
Knows some wx things
Knows some wx things
Posts: 27
Joined: Tue Nov 01, 2005 9:37 pm

Post by fm » Wed Nov 09, 2005 11:44 pm

I finally made it work, made my own rc file, changed capital to normal letter and finally it works. Thank's everyone!

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Wed Nov 09, 2005 11:48 pm

no problem :P

Post Reply