Set Icon 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
Ksawery
Experienced Solver
Experienced Solver
Posts: 83
Joined: Thu Jul 25, 2019 12:31 pm

Set Icon

Post by Ksawery »

Hello,

I'd like to setup an icon for my wxWidgets application, so that it appears both on the .exe file, as well as in the taskbar and top-left corner of each application window. What would be the best way to achieve this? I've searched for a solution for a while now, and I came across posts referring to either .xpm files or .ico files, the SetIcon() method, and using the resource.rc file. After many attempts I was unable to get it to work. I'm not sure if I'm editing the resource.rc contents correctly. Currently, my resource.rc file looks as follows:

Code: Select all

��/ /   M i c r o s o f t   V i s u a l   C + +   g e n e r a t e d   r e s o u r c e   s c r i p t . 
 
 / / 
 
 # i n c l u d e   " r e s o u r c e . h "

 # d e f i n e   A P S T U D I O _ R E A D O N L Y _ S Y M B O L S 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 / / 
 
 / /   G e n e r a t e d   f r o m   t h e   T E X T I N C L U D E   2   r e s o u r c e . 
 
 / / 
 
 # i n c l u d e   " w i n r e s . h " 
 
 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 # u n d e f   A P S T U D I O _ R E A D O N L Y _ S Y M B O L S 
 
 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 / /   E n g l i s h   ( U n i t e d   S t a t e s )   r e s o u r c e s 
 
 
 
 # i f   ! d e f i n e d ( A F X _ R E S O U R C E _ D L L )   | |   d e f i n e d ( A F X _ T A R G _ E N U ) 
 
 L A N G U A G E   2 1 ,   1 
 
 
 
 # i f d e f   A P S T U D I O _ I N V O K E D 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 / / 
 
 / /   T E X T I N C L U D E 
 
 / / 
 
 
 
 1   T E X T I N C L U D E 
 
 B E G I N 
 
         " r e s o u r c e . h \ 0 " 
 
 E N D 
 
 
 
 2   T E X T I N C L U D E     
 
 B E G I N 
 
         " # i n c l u d e   " " w i n r e s . h " " \ r \ n " 
 
         " \ 0 " 
 
 E N D 
 
 
 
 3   T E X T I N C L U D E     
 
 B E G I N 
 
         " \ r \ n " 
 
         " \ 0 " 
 
 E N D 
 
 
 
 # e n d i f         / /   A P S T U D I O _ I N V O K E D 
 
 
 
 # e n d i f         / /   E n g l i s h   ( U n i t e d   S t a t e s )   r e s o u r c e s 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 
 
 
 
 
 
 # i f n d e f   A P S T U D I O _ I N V O K E D 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 / / 
 
 / /   G e n e r a t e d   f r o m   t h e   T E X T I N C L U D E   3   r e s o u r c e . 
 
 / / 
 
 
 
 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 # e n d i f         / /   n o t   A P S T U D I O _ I N V O K E D 
 
 
And per this post:

viewtopic.php?t=13983

I added the following lines to the file:

Code: Select all

aaaa ICON icon.ico
#include <wx/msw/wx.rc>
where icon.ico is a file in the same folder as resource.rc. Then in my OnInit() function I call:

Code: Select all

m_frame1->SetIcon(wxICON(icon));
However I get include errors relating to wx/msw/wx.rc.

Many thanks,
Ksawery
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Set Icon

Post by doublemax »

Code: Select all

m_frame1->SetIcon(wxICON(icon));
Try this instead:

Code: Select all

m_frame1->SetIcon(wxICON(aaaa));
However I get include errors relating to wx/msw/wx.rc.
Post the error message.
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Set Icon

Post by PB »

BTW, if you actually have an icon with multiple sizes of the image (16x16, 32x32,...), I would as always recommend using SetIcons() instead of SetIcon().
Ksawery
Experienced Solver
Experienced Solver
Posts: 83
Joined: Thu Jul 25, 2019 12:31 pm

Re: Set Icon

Post by Ksawery »

Thank you, I changed the code according to your suggestion, but I still get the following include error:

Code: Select all

Severity	Code	Description	File	Line
Error	RC1015	cannot open include file 'wx/msw/wx.rc'.	C:\Users\kwret\Documents\Visual Studio 2019\Projects\PomiarWiazki_wxWidgets\PomiarWiazki_wxWidgets\PomiarWiazki_wxWidgets.rc	15
Am I not pasting the #include statement in the right place in the .rc file?

As for PB's suggestion, I am using only one icon (16x16 in size).
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Set Icon

Post by doublemax »

Check the include paths under project properties -> Resources -> General
Use the source, Luke!
Ksawery
Experienced Solver
Experienced Solver
Posts: 83
Joined: Thu Jul 25, 2019 12:31 pm

Re: Set Icon

Post by Ksawery »

Thanks, that solved the include error, however I now get the following errors:

Code: Select all

Severity	Code	Description	File	Line
Error	RC2135	file not found: ICON	C:\Users\kwret\Documents\Visual Studio 2019\Projects\PomiarWiazki_wxWidgets\PomiarWiazki_wxWidgets\PomiarWiazki_wxWidgets.rc	6
Error	RC2135	file not found: MENU	C:\sdks\wx312\include\wx\msw\wx.rc	21
Error	RC2135	file not found: POPUP	C:\sdks\wx312\include\wx\msw\wx.rc	23
Error	RC2135	file not found: MENUITEM	C:\sdks\wx312\include\wx\msw\wx.rc	25
Error	RC2135	file not found: MENUITEM	C:\sdks\wx312\include\wx\msw\wx.rc	26
The contents of my project .rc file are as follows:

Code: Select all

��/ /   M i c r o s o f t   V i s u a l   C + +   g e n e r a t e d   r e s o u r c e   s c r i p t . 
 
 / / 
 

 # i n c l u d e   " r e s o u r c e . h "

aaaa ICON icon.ico
#include "wx/msw/wx.rc"

 # d e f i n e   A P S T U D I O _ R E A D O N L Y _ S Y M B O L S 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 / / 
 
 / /   G e n e r a t e d   f r o m   t h e   T E X T I N C L U D E   2   r e s o u r c e . 
 
 / / 
 
 # i n c l u d e   " w i n r e s . h " 
 
 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 # u n d e f   A P S T U D I O _ R E A D O N L Y _ S Y M B O L S 
 
 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 / /   E n g l i s h   ( U n i t e d   S t a t e s )   r e s o u r c e s 
 
 
 
 # i f   ! d e f i n e d ( A F X _ R E S O U R C E _ D L L )   | |   d e f i n e d ( A F X _ T A R G _ E N U ) 
 
 L A N G U A G E   2 1 ,   1 
 
 
 
 # i f d e f   A P S T U D I O _ I N V O K E D 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 / / 
 
 / /   T E X T I N C L U D E 
 
 / / 
 
 
 
 1   T E X T I N C L U D E 
 
 B E G I N 
 
         " r e s o u r c e . h \ 0 " 
 
 E N D 
 
 
 
 2   T E X T I N C L U D E     
 
 B E G I N 
 
         " # i n c l u d e   " " w i n r e s . h " " \ r \ n " 
 
         " \ 0 " 
 
 E N D 
 
 
 
 3   T E X T I N C L U D E     
 
 B E G I N 
 
         " \ r \ n " 
 
         " \ 0 " 
 
 E N D 
 
 
 
 # e n d i f         / /   A P S T U D I O _ I N V O K E D 
 
 
 
 # e n d i f         / /   E n g l i s h   ( U n i t e d   S t a t e s )   r e s o u r c e s 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 
 
 
 
 
 
 # i f n d e f   A P S T U D I O _ I N V O K E D 
 
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 / / 
 
 / /   G e n e r a t e d   f r o m   t h e   T E X T I N C L U D E   3   r e s o u r c e . 
 
 / / 
 
 
 

 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
 
 # e n d i f         / /   n o t   A P S T U D I O _ I N V O K E D 
 
Ksawery
Experienced Solver
Experienced Solver
Posts: 83
Joined: Thu Jul 25, 2019 12:31 pm

Re: Set Icon

Post by Ksawery »

Ok, I got it to work, the problem was caused by the two non-sense symbols at the beginning of the resource file: ��

Regards,
Ksawery
Post Reply