visual-c++wxwidgetsembedded-resource.ico

Create resource from existing .ico icon


I have an icon in .ico format. I want to add it as a resource in my VC++ project. I want to set it as the main icon using wxWidgets.

I right click resources, and my choices are existing item and new item. If I select new item and .ico, it brings up a bitmap editor. That can't be right. So I select "existing item" and put foo.ico into the resources. But the following fails:

wxFrame::SetIcon(wxICON(foo));

I have tried various decorations, like foo.ico and wxBITMAP_TYPE_ICO_RESOURCE, yada yada, but I have yet to strike the perfect combination.

Edit: I found something on the net that says I need to create a new resource and add the foo.ico to that. I tried following the instructions, but no joy.


Solution

  • I managed to do it, but there must be a better way.

    I copied a resource file, namely sample.rc, from the wxWidgets samples. I edited it in a text editor, replacing the icon name with foo.ico in a couple of places. I also commented-out an #include that referred to a wxWidget project directory. In Visual Studio, I added that file to the resources. In the MyFrame constructor in my program, I wrote,

    SetIcon(wxICON(sample));
    

    Very hackish, but it worked.