Sign in to follow this  

Some WIN32 Help - resource Files in MSVC Express

This topic is 3953 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do you add them in? I know that MSVC Express 2005 doesnt have an editor and doesnt let you make your own in the IDE itself, but if i create one in another program (like dev or a 3rd party .rc creator) how do i add it into a project? I added the file in the solution explorer's Resource Files folder, but it won't compile, and yes i have the resource.h file. Here's the source files for a basic Win32 App: WinMain.cpp [CODE] #include <windows.h> #include "resource.h" LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("NoPopUps"); HWND hwnd; MSG msg; WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc= WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInst; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground= (HBRUSH) GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName= NULL; wndclass.lpszClassName= szAppName; if(!RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("This Program Requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, TEXT("No-PopUp Nested Menu Demonstration"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HMENU hMenuMain, hMenuEdit, hMenuFile; HINSTANCE hInst; switch(message) { case WM_CREATE: hInst = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE); hMenuMain = LoadMenu(hInst, TEXT("MenuMain")); hMenuFile = LoadMenu(hInst, TEXT("MenuFile")); hMenuEdit = LoadMenu(hInst, TEXT("MenuEdit")); SetMenu(hwnd, hMenuMain); return 0; case WM_COMMAND: switch(LOWORD (lParam)) { case IDM_MAIN: SetMenu(hwnd, hMenuMain); return 0; case IDM_FILE: SetMenu(hwnd, hMenuFile); return 0; case IDM_EDIT: SetMenu(hwnd, hMenuEdit); return 0; case IDM_FILE_NEW: case IDM_FILE_OPEN: case IDM_FILE_SAVE: case IDM_FILE_SAVE_AS: case IDM_EDIT_UNDO: case IDM_EDIT_CUT: case IDM_EDIT_COPY: case IDM_EDIT_PASTE: case IDM_EDIT_CLEAR: MessageBeep(0); return 0; } break; case WM_DESTROY: SetMenu(hwnd, hMenuMain); DestroyMenu(hMenuFile); DestroyMenu(hMenuEdit); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); } [/CODE] Resource.h [CODE] #ifdef __IDMFILE__ #define IDM_FILE 40001 #define IDM_EDIT 40002 #define IDM_FILE_NEW 40003 #define IDM_FILE_OPEN 40004 #define IDM_MAIN 40005 #define IDM_FILE_SAVE 40006 #define IDM_FILE_SAVE_AS 40007 #define IDM_EDIT_UNDO 40008 #define IDM_EDIT_CUT 40009 #define IDM_EDIT_COPY 40010 #define IDM_EDIT_PASTE 40011 #define IDM_EDIT_CLEAR 40012 #endif [/CODE] Resource.rc [CODE] #include "resource.h" #include "afxres.h" MENUMAIN MENU DISCARDABLE BEGIN MENUITEM "MAIN:", 0, INACTIVE MENUITEM "&File...", IDM_FILE MENUITEM "&Edit...", IDM_EDIT END MENUFILE MENU DISCARDABLE BEGIN MENUITEM "FILE:", 0, INACTIVE MENUITEM "&New", IDM_FILE_NEW MENUITEM "&Open...", IDM_FILE_OPEN MENUITEM "&Save", IDM_FILE_SAVE MENUITEM "Save &As", IDM_FILE_SAVE_AS MENUITEM "(&Main)", IDM_MAIN END MENUEDIT MENU DISCARDABLE BEGIN MENUITEM "EDIT:", 0, INACTIVE MENUITEM "&Undo", IDM_EDIT_UNDO MENUITEM "Cu&t", IDM_EDIT_CUT MENUITEM "&Copy", IDM_EDIT_COPY MENUITEM "&Paste", IDM_EDIT_PASTE MENUITEM "De&lete", IDM_EDIT_CLEAR MENUITEM "(&Main)", IDM_MAIN END [/CODE] Now i've never written my own resource files before, so i'm sure there are errors in them or something. The problems i get are the following: Errors: [CODE] ------ Build started: Project: PW - NoPopUps, Configuration: Debug Win32 ------ Compiling... WinMain.cpp c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(45) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(56) : warning C4312: 'type cast' : conversion from 'LONG' to 'HINSTANCE' of greater size c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(68) : error C2065: 'IDM_MAIN' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(68) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(72) : error C2065: 'IDM_FILE' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(72) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(76) : error C2065: 'IDM_EDIT' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(76) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(80) : error C2065: 'IDM_FILE_NEW' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(80) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(81) : error C2065: 'IDM_FILE_OPEN' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(81) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(82) : error C2065: 'IDM_FILE_SAVE' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(82) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(83) : error C2065: 'IDM_FILE_SAVE_AS' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(83) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(84) : error C2065: 'IDM_EDIT_UNDO' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(84) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(85) : error C2065: 'IDM_EDIT_CUT' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(85) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(86) : error C2065: 'IDM_EDIT_COPY' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(86) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(87) : error C2065: 'IDM_EDIT_PASTE' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(87) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(88) : error C2065: 'IDM_EDIT_CLEAR' : undeclared identifier c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(88) : error C2051: case expression not constant c:\documents and settings\doug.laptop.000\my documents\visual studio 2005\projects\pw - nopopups\pw - nopopups\winmain.cpp(91) : warning C4060: switch statement contains no 'case' or 'default' labels Build log was saved at "file://c:\Documents and Settings\Doug.LAPTOP.000\My Documents\Visual Studio 2005\Projects\PW - NoPopUps\PW - NoPopUps\Debug\BuildLog.htm" PW - NoPopUps - 24 error(s), 3 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== [/CODE] Thanks!

Share this post


Link to post
Share on other sites
In your resource.h file (Shown below) you used the preprocessor to
hide the contents (All the #defines) unless __IDMFILE__ is defined.

In other words...
 
//...only include the following code if __IDMFILE__ is defined...
#ifdef __IDMFILE__

#define IDM_FILE 40001
#define IDM_EDIT 40002
#define IDM_FILE_NEW 40003
#define IDM_FILE_OPEN 40004
#define IDM_MAIN 40005
#define IDM_FILE_SAVE 40006
#define IDM_FILE_SAVE_AS 40007
#define IDM_EDIT_UNDO 40008
#define IDM_EDIT_CUT 40009
#define IDM_EDIT_COPY 40010
#define IDM_EDIT_PASTE 40011
#define IDM_EDIT_CLEAR 40012

#endif





You have to #define __IDMFILE__ before including the file
(Or use inclusion guards, and take the #ifdef out)...

#define __IDMFILE__ //Have to insure this is defined because the #ifdef
// in resource.h

#include "resource.h"

I suspect this is the problem. After fixing the above,
it should work just fine.

Share this post


Link to post
Share on other sites
Thanks, i'll take a look, i just wrote something there and i didn't know what i was doing, so i'll play with it, thanks!

Share this post


Link to post
Share on other sites
Okay i cant figure this out, can someone point me in the right direction as far as a tutorial or something about writing resource files and resource.h files?

I'm not formatting it right or something... Or even if anyone could show an example of a resource file and resource.h file.

I dunno how to properly format it and that seems to be the problem

Thanks!

Share this post


Link to post
Share on other sites
Heres the format I always use...

Here is resource.h:

#ifndef RESOURCE_H_INCLUDED
#define RESOURCE_H_INCLUDED

#if defined (_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

// ...Put your resource ID's here...

#endif



resource.rc:

#include "resource.h"

// resources



You have to also inssure to include the files in your project so the resource
compilier (and linker) could produce (and link) the *.res file with the
rest of the project.

You can do this by right-clicking the project (In solution explorer),
and select Add->Existing item and then select your *.rc file in the
project (along with your *.h file)

Everythng should work then.

Share this post


Link to post
Share on other sites
Sign in to follow this