Author Topic: Setting Application Icon How To?  (Read 15622 times)

Offline d88pak

  • Single posting newcomer
  • *
  • Posts: 7
Setting Application Icon How To?
« on: August 25, 2008, 04:49:45 pm »
Hi,

I don't know where the problem lies so I posted on both forums. So far I was not able to get any answer from wxWidgets forum.

I am using:
========================
c::b = 8.02 (without mingw)
MinGW = 3.4.5
wxWidgets = 2.8.8
OS = WindowsXP/SP2
wxSmith as from designer
========================

My application is compiling and working fine but with small problem. The "SetIcon" is not showing the icon on titlebar area of my application.

Details of my problem which I am facing after I posted this problem is here in wxWidgets forum
http://wxforum.shadonet.com/viewforum.php?f=1&sid=86139d894968630872658e38b2b63b91

searching this forum, I stumbled here
http://forums.codeblocks.org/index.php/topic,2191.0.html

Quote
Making the same icon show up in the upper left corner of your program window and in the taskbar is somewhat more complicated.

by TDragon

caught my attention. This means its not a new issue.

Please can somebody explain to me where the problem lies (windows, mingw, wxwidgets, c::b settings etc) and  how to solve it?

Thanks

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7162
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Setting Application Icon How To?
« Reply #1 on: August 25, 2008, 05:52:01 pm »
SetIcon() works for me (at least for framebased apps).

I have an icon-file called "aaaaa_logo.ico" in the projects root-dir.

In the resource-file ("resource.rc" if created by the wizard) I replace the first line (aaaa ICON "wx/msw/std.ico") with aaaaa_logo ICON "aaaaa_logo.ico"

In the constructor I added this line:
Code: [Select]
SetIcon(wxICON(aaaaa_logo));

And that's it.

You might need to place "#include <wx/icon.h>" in your .cpp file

EDIT:

I only tested it on w2k, I normally do not develop on windows (except for web-development and embedded development on beckhoff-components).
But I think it should work on XP also.

Offline d88pak

  • Single posting newcomer
  • *
  • Posts: 7
Re: Setting Application Icon How To?
« Reply #2 on: August 25, 2008, 07:31:49 pm »
Quote
In the resource-file ("resource.rc" if created by the wizard) I replace the first line (aaaa ICON "wx/msw/std.ico") with aaaaa_logo ICON "aaaaa_logo.ico"

I had tried replacing "std.ico" with my own as you said before but running the application shows the icon in taskbar not in the frame window.

I have also tried using icon (absolute path) from wxSmith property window which used to work before but not anymore now.

Most weired thing happned to me now is, even if icon file is embedded in app through rc file, I can see the std.ico in my taskbar.

currently I am checking what codes wxSmith changes automatically. I found out that when I try to set/unset the frame icon from wxSmith's properties, it adds and removes <wx/bitmap.h> and <wx/image.h> respectively.  I noticed this particular bihavior because my application failed to compile when I removed the  frame image (set to no image) since I have other Static bitmap controls in my frame which depends on <wx/bitmap.h> and <wx/image.h> but removed automatically by wxSmith. I guess its the bug in wxSmith failing to check if other dependent controls are present before removing the header file.

I am suspecting wxSmith for this but don't know where to look for. Any clue regarding this?

Thanks

Offline stahta01

  • Lives here!
  • ****
  • Posts: 5779
    • My Best Post
Re: Setting Application Icon How To?
« Reply #3 on: August 26, 2008, 05:34:42 am »
Do you have an short code sample that runs and that shows the problem?

That is the only way I get wxWidgets questions answered; I usual start out with the wxWidgets sample closest to my program and add code till the problem happens.

Tim S

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline d88pak

  • Single posting newcomer
  • *
  • Posts: 7
Re: Setting Application Icon How To?
« Reply #4 on: August 26, 2008, 07:23:35 am »
Quote
Do you have an short code sample that runs and that shows the problem?

That is the only way I get wxWidgets questions answered; I usual start out with the wxWidgets sample closest to my program and add code till the problem happens.

Tim S

I tried creating new wxFrame based Hollow app (from wizard monolithic=1, unicode=1, dynamic liking=1, wxwidget version 2.8.x) and tried setting icon from its properties. Still the same same problem. Nothing is done here yet by hand (all generated code).

Probably the relevant code will be (which is generated by wxSmith):


   
Code: [Select]
Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    {
    wxIcon FrameIcon;
    FrameIcon.CopyFromBitmap(wxBitmap(wxImage(_T("D:\\CODE_BLOCKS_WORKSPACE\\myIconTest\\res\\myicon.png"))));
    SetIcon(FrameIcon);
    }

NOTE: I have tried ICO file also without any progress.

I had posted my intentional code at wxWidgets forum. Please follow the link in my previous post.

For clarity, I had attached two images for reference.

Thanks




[attachment deleted by admin]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 5779
    • My Best Post
Re: Setting Application Icon How To?
« Reply #5 on: August 27, 2008, 02:57:05 am »
It works for me; without an sample program with the problem it is a waste of time to try duplicate the problem.

Tim S

I used C::B Wizard using these options.

File -> New -> Project
wxWidgets Project
2.8.x
GUI none
App type: Frame

The wizard made this code method

Code: [Select]
bool TestFrameIconApp::OnInit()
{
    TestFrameIconFrame* frame = new TestFrameIconFrame(0L, _("wxWidgets Application Template"));
    frame->SetIcon(wxICON(aaaa)); // To Set App Icon
    frame->Show();
   
    return true;
}
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline d88pak

  • Single posting newcomer
  • *
  • Posts: 7
Re: Setting Application Icon How To?
« Reply #6 on: August 27, 2008, 09:45:06 am »
Code: [Select]
bool TestFrameIconApp::OnInit()
{
    TestFrameIconFrame* frame = new TestFrameIconFrame(0L, _("wxWidgets Application Template"));
    frame->SetIcon(wxICON(aaaa)); // To Set App Icon  //AND THIS PIECE OF CODE WAS NOT THERE IN MY CASE
    frame->Show();
   
    return true;
}


Thank you very much for solving the problem in simple and elegant way. The piece of code was not there in my "...App.cpp" but instead it was inserted by wxSmith in "...Main.cpp", which I posted earlier. Inserting the line of code by hand in my "...App.cpp" solved all my problem like magic.
My generated code was "myIconTestApp.cpp":

Code: [Select]
#include "myIconTestApp.h"

//(*AppHeaders
#include "myIconTestMain.h"
#include <wx/image.h>
//*)

IMPLEMENT_APP(myIconTestApp);

bool myIconTestApp::OnInit()
{
    //(*AppInitialize
    bool wxsOK = true;
    wxInitAllImageHandlers();
    if ( wxsOK )
    {
    myIconTestFrame* Frame = new myIconTestFrame(0);
    Frame->SetIcon(wxICON(aaaa)); // this was inserted and everything worked fine
    Frame->Show();
    SetTopWindow(Frame);
    }
    //*)
    return wxsOK;

}


So question is
#why this line of code was not generated automatically when wxSmith was used?
#why do wxSmith inserted wxFrame->SetIcon("someicon.ico") in "...Main.cpp" instead of "...App.cpp"?
#why SetIcon in "...Main.cpp" is not working while another way around is?

Well... this will be another topic of discussion (or newbie like me needs some learning to do) but my problem in hand is solved.

Thank you very much and Regards!



Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7162
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Setting Application Icon How To?
« Reply #7 on: August 27, 2008, 10:23:58 am »
I wonder why the wxSmith generated code does not work for you.

I tried it on w2k and on XP, both worked fine with SetIcon in the "xxxMain.cpp".
The only thing I have to change manually is the resource-file, so that the exe has my own icon and not the wxWidgets standard icon in the explorer.

Offline Calvin

  • Single posting newcomer
  • *
  • Posts: 1
Re: Setting Application Icon How To?
« Reply #8 on: March 07, 2014, 09:37:15 pm »
Well I had the same problem with Dialog based app. Here is how I managed to put the icon in the Dialog :

Resource first line:

FROG ICON "adium.ico"

In (YourProject)Main.cpp file:

#include "wx/icon.h"
/*

Your code

*/

void (YourPorject)Dialog::OnInit(wxInitDialogEvent& event)
{

    SetIcon(wxICON(FROG));
}

and it appears !

Offline gtafan

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Setting Application Icon How To?
« Reply #9 on: April 18, 2017, 12:48:24 pm »
SetIcon() works for me (at least for framebased apps).

I have an icon-file called "aaaaa_logo.ico" in the projects root-dir.

In the resource-file ("resource.rc" if created by the wizard) I replace the first line (aaaa ICON "wx/msw/std.ico") with aaaaa_logo ICON "aaaaa_logo.ico"

In the constructor I added this line:
Code: [Select]
SetIcon(wxICON(aaaaa_logo));

And that's it.

You might need to place "#include <wx/icon.h>" in your .cpp file

EDIT:

I only tested it on w2k, I normally do not develop on windows (except for web-development and embedded development on beckhoff-components).
But I think it should work on XP also.
Sorry for diging this really old thread, but have also a problem with seting the icon of a frame and this solution doesn´t worck for me. Geting error mesage from compiler like: "aaaa was not declared". In my .rc file the icon is just called aaaa, not aaaaa_logo, so my line of code also looks like that:

Code: [Select]
SetIcon(wxICON(aaaaa));In some way the error mesage make sence, but how to fix that? <wx/icon.h> was included.