-
Dev Resource problem
I'm using Dev C++ 5, and i've copied this source from a tutorial in a book. The problem is when i try and compile it before it compiles it says "cannot create makefile". It only ever seems to happen with resources.
Main.cpp
Code:
#include <windows.h>
#include "Menu.h"
const char *ClsName = "BasicApp";
const char *WndName = "A Simple Window";
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HWND hWnd;
WNDCLASSEX WndClsEx;
// Create the application window
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = "MyMenu";
WndClsEx.lpszClassName = ClsName;
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// Register the application
RegisterClassEx(&WndClsEx);
// Create the window object
hWnd = CreateWindow(ClsName,
WndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
// Find out if the window was created
if( !hWnd ) // If the window was not created,
return 0; // stop the application
// Display the window to the user
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
// Decode and treat the messages
// as long as the application is running
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
int responce;
switch(Msg)
{
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDM_ALPHA:
MessageBox(hWnd, "Alpha", "Alpha", MB_OK);
break;
case IDM_BETA:
MessageBox(hWnd, "Beta", "Beta", MB_OK);
break;
case IDM_EXIT:
responce = MessageBox(hWnd, "Quit the programme?", "Exit",
MB_YESNO);
if ( respone == IDYES ) PostQuitMessage(0);
break;
case IDM_GAMMA:
MessageBox(hWnd, "Gamma", "Gamma", MB_OK);
break;
case IDMEPSILON:
MessageBox(hWnd, "Epsilon", "Epsilon", MB_OK);
break;
case IDM_ZETA:
MessageBox(hWnd, "Zeta", "Zeta", MB_OK);
break;
case IDM_ETA:
MessageBox(hWnd, "Eta", "Eta", MB_OK);
break;
case IDM_THETA:
MessageBox(hWnd, "Theta", "Theta", MB_OK);
break;
case IDM_HELP:
MessageBox(hWnd, "No help", "No Help", MB_OK);
}
break;
// If the user wants to close the application
case WM_DESTROY:
// then close it
PostQuitMessage(WM_QUIT);
break;
default:
// Process the left-over messages
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
// If something was not done, let it go
return 0;
}
Main.h
Code:
#define IDM_ALPHA 100
#define IDM_BETA 101
#define IDM_EXIT 102
#define IDM_GAMMA 103
#define IDM_DELTA 104
#define IDM_EXSILON 105
#define IDM_ZETA 106
#define IDM_ETA 107
#define IDM_THETA 108
#define IDM_HELP 109
Main.rc
Code:
#include "menu.h"
MyMenu MENU
{
POPUP "&One"
{
MENUITEM "&Alpha" IDM_ALPHA
MENUITEM "&Beta" IDM_BETA
MENUITEM "E&xit" IDM_EXIT
}
POPUP "&Two"
{
MENUITEM "&Gamma" IDM_GAMMA
POPUP "&Delta"
{
MENUITEM "&Epsilon" IDM_EPSILON
MENUITEM "&Zelta" IDM_ZELTA
}
MENUITEM "&Epsilon" IDM_EPSILON
MENUITEM "&Theta" IDM_THETA
}
MENUITEM "&Help" IDM_HELP
}
Anybody here who can help. I think it's just a dev c++ error.
-
Well, I'm assuming you messed up in posting that your header is called Main.h, since it says menu.h in your resource. And yes, it is a Dev C++ thing. I encountered the exact same thing, and the solution isn't something most tutorials tell you to do. What you have to do is include windows.h in both your resource AND your source code. That'll clear it right up. I didn't have a problem with Menus, though, only Dialogs, but there was another member on here that said he had menu resource problems, and I use C instead of C++.
NOTE: Although, I notice that you have IDM_EPSILON used in your resource, but IDM_EXSILON used in your *.h. You might want to take note that with resources, a SYNTAX error will occur if you use an ID that isn't #defined. Anything with a # sign is preprocessed, meaning that your code is actually changed before it ever goes to a compiler. If you #define PI to be 3.14, at That line of code actually never gets compiled. What your program does is whenever it sees PI in your code, it deletes it and puts 3.14 in its place.
So, basically the resource is expecting a number in that line of code, but since IDM_EPSILON isn't defined, it's just getting a bunch of characters, whch aren't supposed to be there. Thus, a Syntax error.
-
now i've got a problem where i've cleared all the errors (silly mistakes (mostly spellings of the stupid idmnames)) and now when i compile dev c++ brings up this file called menus_private.rc. I didn't make it and all it contins is this.
Code:
/* THIS FILE WILL BE OVERWRITTEN BY DEV-C++ */
/* DO NOT EDIT! */
#include "Untitled1.rc"
Then the compilation error is that Untitled1.rc does not exist. If i delete the file, when i compile it creates itself again. Does anybody know what is wrong here.
Thanks in advance.
-
Dev C++ is wierd, but that error is very simple. Basically, whenever you create a new resource, it asks you if you want to add it to your current project. If you do, it automatically opens the new resource and creates its own *.rc file, which is what you're seeing. That's how Dev adds resources to a project. At the time when Dev adds your resource to its *.rc, the resource is named Untitled.rc, since it's brand new. The really stupid thing, though, is that it will never change this, so if you save your resource with a different name, Dev is still looking for Untitled.rc. Basically, you could either choose not to add the resource ot your project when you first create it and then add it later, or you could just wait till you get that error and replace Untitled.rc with whatever your resource's name is.