Skip to main content



      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 UserFriend
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
Eclipse UserFriend
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: Mon May 12 16:57:40 EDT 2025

Powered by FUDForum. Page generated in 0.04559 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top