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.
#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.
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.