The first icon in your resource file will be used as the icon of the executable. You'll have to create your resource file manually though, AFAIK Code::Blocks does not have a dialog for it like Dev-cpp. It's not extremely hard, just put something like this in it:
MY_ICON ICON "my_icon.ico"
The first word is the name of the icon (not important unless you want to refer to it in your code), the second word indicates it's an icon and then comes the name of the file to use.
if you use wxWidgets, its as easy as calling SetIcon() in the frame-constructor.
// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------
// frame constructor
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
// set the frame icon
SetIcon(wxICON(sample));
...
}
if you are using plain win32 API, you have to give it as parameter to your WindowsClass structure
see IDR_ICO_MAIN resource ID application-icon, defined in the resource.h file.
int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,
LPSTR lpcmdline,int ncmdshow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX winclass;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS;
winclass.lpfnWndProc = MainWindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WIN_CLASS_NAME;
winclass.hIconSm = NULL;
hinstance_main = hinstance;
if (!RegisterClassEx(&winclass))
return(0);
if (!(hwnd = CreateWindowEx(0,WIN_CLASS_NAME,
"Tutorial Window",
WS_TILEDWINDOW | WS_MAXIMIZEBOX | WS_SIZEBOX ,
0 ,0 ,200,500,NULL,NULL,hinstance,NULL)))
return(0);
InitCommonControls();
ShowWindow(hwnd, SW_SHOW);
main_window_handle = hwnd;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
And you put your icon in the resource.rc file
// resource.rc
IDR_ICO_MAIN ICON "main.ico"
that's it
But I'm not sure how to define my icon in the header file?
I have this in the RC file:
IDR_ICO_MAIN ICON "c:\code\somefolder\someicon.ico"
How do I define that in the .h file? Because I can't compile it otherwise.
the identifier is just a unique number in your program
#define IDR_ICO_MAIN 1234
please work through some tutorials regarding windows programming...
start here
http://www.winprog.org/tutorial/