User forums > General (but related to Code::Blocks)

Setting Application Icon How To?

<< < (2/2)

stahta01:
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: ---bool TestFrameIconApp::OnInit()
{
    TestFrameIconFrame* frame = new TestFrameIconFrame(0L, _("wxWidgets Application Template"));
    frame->SetIcon(wxICON(aaaa)); // To Set App Icon
    frame->Show();
   
    return true;
}

--- End code ---

d88pak:

--- Code: ---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;
}
--- End code ---


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: ---#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;

}

--- End code ---


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!


Jenna:
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.

Calvin:
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 !

gtafan:

--- Quote from: jens 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: --- SetIcon(wxICON(aaaaa_logo));

--- End code ---

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.

--- End quote ---
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: ---SetIcon(wxICON(aaaaa));
--- End code ---
In some way the error mesage make sence, but how to fix that? <wx/icon.h> was included.

Navigation

[0] Message Index

[*] Previous page

Go to full version