Titlebar icon from exe?

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
ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Titlebar icon from exe?

Post by ninja9578 » Mon Feb 23, 2009 9:21 pm

Is there a way to change the icon on the titlebar of my main window to be the one that is embedded in the executable? I've searched the forums and google, but can't find what I'm looking for.

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Mon Feb 23, 2009 10:07 pm

Hi,

Pretty well every frame/dialog etc. type derives from wxTopLevelWindow, so you can call myFrame->SetIcon()

See http://docs.wxwidgets.org/stable/wx_wxt ... dowseticon

If you're using windows, you can get the same icon from your resource file.

Code: Select all

frame->SetIcon(wxIcon(wxT("ICON_MAIN")));
Hope that helps,

Jim
OS: Vista SP1, wxWidgets 2.8.7.

computerquip
Experienced Solver
Experienced Solver
Posts: 72
Joined: Fri Feb 20, 2009 7:13 pm
Location: $(#wx)\src

Post by computerquip » Mon Feb 23, 2009 10:34 pm

Icons are usually dealt with within a .rc file (Resource File) but can be implemented in a class file as well. I'll give examples of both.

Code: Select all

aaaa ICON "wx/msw/std.ico"
//This is generated by Code::Blocks
#include "wx/msw/wx.rc"
This is an example implemented inside of a resource file. This is a LOT more simple than a C++ implementation.

For the C++ implementation, I'll of course use the built-in class called wxIcon.

Code: Select all

wxIcon icon(wxT("std.ico"), wxBITMAP_TYPE_ICO);
<toplevelwindow>->SetIcon(icon);
EDIT: I completely forgot to mention that SetIcon needs to be called in both versions of this. Icon being either the location of the icon in comparison to the program itself or being the name of the icon inside the embedded resource file. In this case, the resource file gives it the name of aaaa.

This is only valid for a wxTopLevelWindow for any of these of course. The resource file is more convenient and I believe there are some other features that come with it.
Also, I've never really tried but I'm not sure if you can embed the icon in your application if you use a C++ implemented function. I may be wrong.
Last edited by computerquip on Wed Feb 25, 2009 10:58 pm, edited 2 times in total.

ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Post by ninja9578 » Tue Feb 24, 2009 2:11 pm

I would really like to not have to package my software with the resource file. The resource file is embedded into the exe at compile time, like with most programs. Is there no way to get it out?

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Tue Feb 24, 2009 2:16 pm

Hi,

My post above is what I use to get the icon from the resource file, change "ICON_MAIN" to whatever label you've given your icon in your resource file.

Jim
OS: Vista SP1, wxWidgets 2.8.7.

Post Reply