Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Newbie question about resource.rc file
Newbie question about resource.rc file [message #201540] Thu, 13 September 2007 11:15 Go to next message
Eclipse User
Originally posted by: edstrasser.hotmail.com

I'm new to Eclipse and C++. I believe my issue is with Eclipse, please
correct me if I'm wrong.

The problem is that my program only displays a generic icon instead of the
custom icon I've defined. I believe that maybe I haven't told Eclipse
where to locate the .ico file and this is causing it not to display.

Below are my code files:

// RESOURCE.H
--------------------------------------------------------
#define IDI_MYICON 101


// WINDOWSFORM.RC
--------------------------------------------------------
#include "resource.h"
#include <windows.h>

IDI_MYICON ICON "U:\Etronics\Documents\Icon\32x32.ico"

// WINDOWFORM.CPP
--------------------------------------------------------
#include <windows.h>
#include "resource.h"

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
// wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Etronics, Inc.",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);

if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Re: Newbie question about resource.rc file [message #201557 is a reply to message #201540] Thu, 13 September 2007 11:30 Go to previous message
Edzard Egberts is currently offline Edzard Egberts
Messages: 57
Registered: July 2009
Member
Ed schrieb:

> I believe that maybe I haven't told
> Eclipse where to locate the .ico file and this is causing it not to
> display.

It's more complicated, you must "compile" your icon to a library like
"libIcon.a". See http://www.gnu.org/software/binutils/ for "Windres" the
"Compiler for Windows resource files". For execution "windres" you need
to install MSYS I think. After that you can use the MSYS bash for
something like "windres MyIcon.rc libicon.a" and then use eclipse
properties to link "icon" into your software.

HTH,

Ed
Previous Topic:Undefined symbols
Next Topic:Eclipse JEE and CDT
Goto Forum:
  


Current Time: Wed Jul 23 22:20:39 EDT 2014

Powered by FUDForum. Page generated in 0.02516 seconds