[Dev-C++] Problem with resource file
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Singh, M. \(GE C. F. NonGE\) <mah...@ge...> - 2004-06-06 17:39:09
|
I am new to DevC++ so please bare with me.
I have been reading the tutorial Win32 API Tutorial
by theForger.=20
According to the Chapter Menus and Icons in the tutorial, I have created =
a .c file, .h file and .rc file containing MENNU definition and ICON =
definition.
Just to inform you I created all this without creating any project.
When I complied the code , it compiles and runs but it does not show the =
menu and the icons.
So, I thought I have to create a project. So I created a project in the =
directory where I had my files. And I included the .c, .h and .rc file. =
And when I complied it gave me this error
###################################
Compiler: Default compiler
Building Makefile: "F:\Cygwin\home\mahen\Personal\cpp\Makefile.win"
Executing make...
make.exe -f "F:\Cygwin\home\mahen\Personal\cpp\Makefile.win" all
windres.exe -i Learning_private.rc -I rc -o Learning_private.res -O coff =
windres.exe: can't popen `gcc -E -xc -DRC_INVOKED Learning_private.rc': =
Invalid argument
make.exe: *** [Learning_private.res] Error 1
Execution terminated
##################################
This is the content of the .h file
#################################
#define IDR_MYMENU 101
#define IDI_MYICON 201
#define ID_FILE_EXIT 9001
#define ID_STUFF_GO 9002
##################################
This is the content of .rc file
##################################
#include "resource.h"
IDR_MYMENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
=20
POPUP "&Stuff"
BEGIN
MENUITEM "&Go", ID_STUFF_GO
MENUITEM "G&o Somewhere else", 0, GRAYED
END
END
IDI_MYICON ICON "menu_one.ico"
##################################
and this the code of .c file
#################################
#include <windows.h>
#include "resource.h"
const char g_szClassName[] =3D "myWindowClass";
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM =
lParam) {
switch(msg) {
case WM_CLOSE:=20
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_MOUSEWHEEL : {
char szFileName[MAX_PATH];
HINSTANCE hInstance =3D GetModuleHandle(NULL);
=20
GetModuleFileName(hInstance, szFileName, MAX_PATH);
MessageBoxA(hwnd, szFileName, "Mahen Testing", MB_OK | =
MB_ICONINFORMATION);
} =20
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam); =20
} =20
} =20
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR =
lpCmdLine, int nCmdShow) {
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
wc.cbSize =3D sizeof(WNDCLASSEX);
wc.style =3D 0;
wc.lpfnWndProc =3D WndProc;
wc.cbClsExtra =3D 0;
wc.cbWndExtra =3D 0;
wc.hInstance =3D hInstance;
wc.hIcon =3D LoadIcon(GetModuleHandle(NULL), =
MAKEINTRESOURCE(IDI_MYICON));
wc.hCursor =3D LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground =3D (HBRUSH)(COLOR_BTNFACE);
wc.lpszMenuName =3D MAKEINTRESOURCE(IDR_MYMENU);
wc.lpszClassName =3D g_szClassName;
wc.hIconSm =3D (HICON)LoadImage(GetModuleHandle(NULL), =
MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
=20
if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "Window Registration Failed!", "Error!", =
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
=20
hwnd =3D CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Testing Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
240, 120,
NULL, NULL, hInstance, NULL);
=20
if(hwnd =3D=3D NULL) {
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
=20
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
=20
while(GetMessageA(&Msg, NULL, 0, 0) > 0) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
} =20
=20
return Msg.wParam;
=20
} =20
#################################
And this is the text of the Makefile.win which DevC++ created
################################
# Project: Learning
# Makefile created by Dev-C++ 4.9.8.9
CPP =3D g++.exe -D__DEBUG__
CC =3D gcc.exe -D__DEBUG__
WINDRES =3D windres.exe
RES =3D Learning_private.res
OBJ =3D simple_window.o $(RES)
LINKOBJ =3D simple_window.o $(RES)
LIBS =3D -L"D:/Dev-Cpp/lib" -lgmon -pg -g3=20
INCS =3D -I"D:/Dev-Cpp/include"=20
CXXINCS =3D -I"D:/Dev-Cpp/include/c++" =
-I"D:/Dev-Cpp/include/c++/mingw32" -I"D:/Dev-Cpp/include/c++/backward" =
-I"D:/Dev-Cpp/include"=20
BIN =3D Learning.exe
CXXFLAGS =3D $(CXXINCS) -pg -g3
CFLAGS =3D $(INCS) -pg -g3
.PHONY: all all-before all-after clean clean-custom
all: all-before Learning.exe all-after
clean: clean-custom
rm -f $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CC) $(LINKOBJ) -o "Learning.exe" $(LIBS)
simple_window.o: simple_window.c
$(CC) -c simple_window.c -o simple_window.o $(CFLAGS)
Learning_private.res: Learning_private.rc menu.rc=20
$(WINDRES) -i Learning_private.rc -I rc -o Learning_private.res -O coff =
##################################
Please help me as I want to learn this Win32API and am new to it.
Thanx
Mahendra
|