Having a few problems with resources. Im just getting the basics on Windows programming and I want to get the resources to work to see if im understand this any better. I have some code below, and a compiler error. I was hoping anyone could tell me how to fix this, or help in fixing it? Example :
Code:
#include <windows.h>
#include "resources.h"
#include "resources.rc"
const char gzWindow[] = "WinApp";
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_RBUTTONDOWN:
{
char szFname[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, szFname, MAX_PATH);
MessageBox(hwnd, szFname, "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;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpszMenuName = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MYMENU)); // is this right?
wc.lpszClassName = gzWindow;
if (!RegisterClassEx(&wc))
{
MessageBox(NULL, "windows reg error", "win reg error",
MB_OK | MB_ICONEXCLAMATION);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
gzWindow,
"Test",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
if (hwnd == NULL)
{
MessageBox(NULL, "wincreate error", "wincreate error",
MB_OK | MB_ICONEXCLAMATION);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
I have the resource info below also, but im wondering where should I declare my menu itself in there, if where I have it is not correct also.
I also get a 'gzWindow undeclared', error, when it's obvious it's declared as a constant global at the begining of the program.
And a 'IDR_MYMENU', undeclared when it is included at the begnning of the program in "resources.rc", also.
Code:
#include "resources.h"
IDR_MYMENU MENU
BEGIN
POPUP "&FILE!"
BEGIN
MENUITEM "C&LOSE!", ID_FILE_EXIT
END
END
And that's my resource file, but I also get a compiler error saying that 'IDR_MYMENU', does not name a type.
And that's about it, (I hope someone even felt like reading this :P)
if you can take some time, to glance through it and explain where I went wrong, and how to fix it id be very appreciated. Thanks, Hitachi.