Problem accessing resource and script file information

Hi everybody,

I'm beginner in C++ windows programming. I'm using Dev-C++ compiler. Does anyone know what can cause a main.cpp file to fail to access information defined in a resource file or script file? This is preventing me from creating menus, loading bitmap images or icon items.

In fact the application is compiling with no error and is running, but the menu I defined in the resource file (resource.h for instance) and whose scripting is in the script.rc file is not appearing in my window. Same thing for personnalised cursors.

I've already succeeded to display menus and personnalized cursors before, so I think it's not a problem of coding.

Anyone who can help please?
When I used Dev-C++ I used the forgers win tutorial and resources worked fine for me.
Sure its not a prob in your resource files?
Ok let's say my resource.h file contains:
1
2
3
4
5
6
7
8
9
10
11
12
#define ID_MENU             501
#define IDI_ICON1           103
#define IDB_BITMAP1         105
#define IDC_CURSOR1         400


#define IDM_FILEVIEWTABLE   200
#define IDM_FILESETTINGS    201
#define IDM_FILEEXIT        202
#define IDM_HELPCONTENTS    203
#define IDM_HELPSEARCH      204
#define IDM_HELPABOUT       205 


Then my script.rc file contains:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <windows.h>
#include "C:\Dev-Cpp\Projects\resource.h"

501 MENU

BEGIN
	POPUP "&File"
	BEGIN
                                MENUITEM "View Table", IDM_FILEVIEWTABLE
		MENUITEM "&Settings...", IDM_FILESETTINGS
		MENUITEM SEPARATOR
		MENUITEM "&Exit", IDM_FILEEXIT
	END
	
                POPUP "&Help"
	BEGIN
		MENUITEM "&Contents\tF1", IDM_HELPCONTENTS
		MENUITEM "&Search", IDM_HELPSEARCH
		MENUITEM SEPARATOR
		MENUITEM "&About...", IDM_HELPABOUT
	END
END



IDI_ICON1               ICON     "C:\\Dev-Cpp\\Icons\\Software.ico"
IDB_BITMAP1             BITMAP   "C:\\Dev-Cpp\\Icons\\Globe.bmp"
IDC_CURSOR1             CURSOR   "C:\\WINDOWS\\Cursors\\pen_rl.cur"


Later in my main.cpp file I use the following lines of code to access my resources:

1
2
3
4
5
6
7
8
9
wincl.hCursor = reinterpret_cast<HICON>(LoadImage(hThisInstance, MAKEINTRESOURCE(IDC_CURSOR1),IMAGE_CURSOR,0,0, LR_DEFAULTCOLOR)); //for the cursor

HBITMAP hBmp=reinterpret_cast<HBITMAP>(LoadImage(hThisInstance, MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION));        
wincl.hbrBackground = CreatePatternBrush(hBmp); //bitmap used to create background
DeleteObject(hBmp);  

menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU));
SetMenu(hwnd, menu); //to display menu after the window is created and displayed


Is there anywhere I messed up with my code? Understand I'm still newbie, so I can make stupid mistakes.

Thanks

Just forget it. I found a way to solve my problem. I'm creating my menu straight in the WM_CREATE handler and it is working. So, basically, i'm not using resources anymore. However, i'm still wondering why my code above didn't work.

Thanks enixi0s for referencing me to The Forgers Win Tutorial.
Last edited on
Topic archived. No new replies allowed.