|
-
February 19th, 2006, 05:51 PM
#1
New to Win32
I have a resource file that defines my menu for my window. Now the program compiles fine when I don't include the resource file in my project but when I do, I get and error saying "No rule to make target 'all'. What does this mean and what am I doing wrong? Here is the code I have for the project.
MAIN WINDOWS CODE:
#include <windows.h>
#include "resource.h"
//windows class name
const char g_szClassName[] = "myWindowClass";
//the windows procedure
//this handles all the messages sent to the window
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
switch(msg){
case WM_LBUTTONDOWN:
{
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
MessageBox(hwnd, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
//the main window function
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
//variable declarations and initializations
//instance of the extended window class
WNDCLASSEX wc;
//window handle
HWND hwnd;
//instance of the message class
MSG Msg;
//register 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.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
//check to see if the class failed to register
if(!RegisterClassEx(&wc)){
MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
//create the window
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "The Title of my Window",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
//check to see if the window create failed
if(hwnd == NULL){
MessageBox(NULL, "Window Creation Failed", "Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
//draw the window
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
//the message loop
while(GetMessage(&Msg, NULL, 0, 0) > 0){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
RESOURCE.H:
#define IDR_MYMENU 101
#define ID_FILE_EXIT 9001
#define ID_STUFF_GO 9002
MENU.RC:
#include "resource.h"
IDR_MYMENU MENU
BEGIN
POPUP "$File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Stuff"
BEGIN
MENUITEM "&Go", ID_STUFF_GO
MENUITEM "G&o Somewhere Else", 0, GRAYED
END
END
-
February 19th, 2006, 07:29 PM
#2
Re: New to Win32
Unfortunately, this isn't a compiler problem. You have a problem with your make file or your linker or maybe even your project file. If you're new, that won't be very helpful... :-(
What compiler and IDE are you using? I'll probably only be able to help if you're using mingw with dev-cpp, as I don't use visual c, but maybe someone else will help you out.
-
February 19th, 2006, 09:12 PM
#3
Re: New to Win32
I'm using Dev-C++.
I think it might be the linker because I retyped this code three times into three separate projects and it still gives me the error.
-
February 19th, 2006, 09:37 PM
#4
Re: New to Win32
I just encountered the problem myself.. lol
How i solved it was I went into my project directory and deleted all of the .o files, and the make file, and the rc files that are marked private, then I went rebuild all.
What probably happaned is you went to create a new resource file, and it gave you a file called untitled1.rc. Then you put in your rc script, and renamed the file to resource.rc... (that's what I did)
Renaming the file crashed the resorce compiler inside dev-cpp... because dev-cpp actually creates a resource file called private_something.rc which includes your resource file.... and now the include fails cause you've renamed the file, and it dies.... stupid bug.... dev-cpp is full of them.
Most of them can be solved by closing, deleting all the temp files in your directory, reopening, and clicking rebuild all from the menu.
-
February 20th, 2006, 12:40 AM
#5
Re: New to Win32
So basically don't rename the resource file and delete all the temp files?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|