General Question MFD Development -- what is a resource file?

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
Hello everyone,

I've been considering MFD development recently, as I would like to be able to create a few tools for various things in Orbiter. I now feel that I have a fairly strong grasp of the C++ language, but I know very little about the specifics in creating an MFD.

I have the CustomMFD solution set up in Visual Studio 2010 now, but the solution has a CustomMFD.rc resource file and a resource.h header defined, but not included for the project to use. What exactly is a resource file, and how is it supposed to be used?
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36

Okay, but what is the point of putting preprocessor directives in an RC, instead of the main code itself? I cant seem to open RC files in visual studio anyways.

Edit: I can open RC's with notepad, but I still dont recognize the syntax. Will need to research this a bit.
 
Last edited:

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,216
Reaction score
1,562
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
Non-Express versions of Visual Studio make adding and using project resources easy -- it reads/updates/generates the .rc files for you from the IDE. However, if you are using the Express edition of Visual Studio it does not support reading or creating resource files in its IDE -- in that case you will need to edit the resource files manually (which is a pain) or use an external resource file editor to automate some of it. For more information, see here.
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
Non-Express versions of Visual Studio make adding and using project resources easy. However, if you are using the Express edition of Visual Studio it does not support creating resource files in its IDE -- in that case you will need to edit the resource files manually (which is a pain) or use an external resource file editor to automate some of it. For more information, see here.

Thanks. But, as I mentioned above, what is the point of using an RC for preprocessor directives instead of putting them in the code itself?
 

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,216
Reaction score
1,562
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
Resource files end with .rc and are not C++ files -- they have a different syntax and are compiled by the resource compiler, not the C++ compiler. Yes, the resource compiler runs them through the preprocessor just like .cpp and .h files are by the C++ compiler, but that is beside the point. :) Resource files define resources for your DLL or EXE file, which are icons, bitmaps, dialog box definitions, or other data files you want to bundle inside your EXE or DLL.

Here is a portion of Orbitersdk\samples\DeltaGlider\DeltaGlider.rc included with the Orbiter SDK.

Code:
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.K.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
#ifdef _WIN32
[COLOR="Green"]LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK[/COLOR]
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//

[COLOR="Green"]
IDB_DIAL1               BITMAP                  "Bitmaps\\Dial1.bmp"
IDB_NAVBUTTON           BITMAP                  "Bitmaps\\Navbutton.bmp"
IDB_SWITCH1             BITMAP                  "Bitmaps\\Switch1.bmp"
IDB_LIGHT1              BITMAP                  "Bitmaps\\Light1.bmp"
IDB_INDICATOR           BITMAP                  "Bitmaps\\Indicator.bmp"
IDB_SLIDER1             BITMAP                  "Bitmaps\\Slider1.bmp"
[/color]
[I]... snip...[/I]

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

[COLOR="Green"]IDD_CTRL DIALOGEX 0, 0, 133, 207
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "DG Controls"
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
    GROUPBOX        "Landing gear",IDC_STATIC,7,4,57,40
    CONTROL         "Up",IDC_GEAR_UP,"Button",BS_AUTORADIOBUTTON | BS_PUSHLIKE | WS_GROUP,14,16,43,11
    CONTROL         "Down",IDC_GEAR_DOWN,"Button",BS_AUTORADIOBUTTON | BS_PUSHLIKE,14,29,43,11
    GROUPBOX        "Nose cone",IDC_STATIC,7,90,57,40
    CONTROL         "Close",IDC_NCONE_CLOSE,"Button",BS_AUTORADIOBUTTON | BS_PUSHLIKE | WS_GROUP,14,101,43,11[/COLOR]
[I]... continues ...[/I]

I highlighted the resource file syntax in green above. So it's not a matter of "putting processor directives in an .rc file instead of a .h or .cpp file", it's a matter of defining resources using the resource file syntax and (as necessary) using preprocessor directives to conditionally include or exclude blocks of code just like .cpp and .h files do.

Non-Express versions of Visual Studio read and generate .rc files automatically from the built-in resource editor, which makes it easy to add resources and design dialogs. However, if you have Visual Studio Express and need to add resources manually the first thing I would do is read up on the resource file syntax so you can read and write them manually using a text editor. Or you can locate a resource editor from this link in my previous post.
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
Resource files end with .rc and are not C++ files -- they have a different syntax and are compiled by the resource compiler, not the C++ compiler. Yes, the resource compiler runs them through the preprocessor just like .cpp and .h files are by the C++ compiler, but that is beside the point. :) Resource files define resources for your DLL or EXE file, which are icons, bitmaps, dialog box definitions, or other data files you want to bundle inside your EXE or DLL.

Here is a portion of Orbitersdk\samples\DeltaGlider\DeltaGlider.rc included with the Orbiter SDK.

Code:
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.K.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
#ifdef _WIN32
[COLOR="Green"]LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK[/COLOR]
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//

[COLOR="Green"]
IDB_DIAL1               BITMAP                  "Bitmaps\\Dial1.bmp"
IDB_NAVBUTTON           BITMAP                  "Bitmaps\\Navbutton.bmp"
IDB_SWITCH1             BITMAP                  "Bitmaps\\Switch1.bmp"
IDB_LIGHT1              BITMAP                  "Bitmaps\\Light1.bmp"
IDB_INDICATOR           BITMAP                  "Bitmaps\\Indicator.bmp"
IDB_SLIDER1             BITMAP                  "Bitmaps\\Slider1.bmp"
[/color]

[I]... snip...[/I]

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

[COLOR="Green"]IDD_CTRL DIALOGEX 0, 0, 133, 207
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "DG Controls"
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
    GROUPBOX        "Landing gear",IDC_STATIC,7,4,57,40
    CONTROL         "Up",IDC_GEAR_UP,"Button",BS_AUTORADIOBUTTON | BS_PUSHLIKE | WS_GROUP,14,16,43,11
    CONTROL         "Down",IDC_GEAR_DOWN,"Button",BS_AUTORADIOBUTTON | BS_PUSHLIKE,14,29,43,11
    GROUPBOX        "Nose cone",IDC_STATIC,7,90,57,40
    CONTROL         "Close",IDC_NCONE_CLOSE,"Button",BS_AUTORADIOBUTTON | BS_PUSHLIKE | WS_GROUP,14,101,43,11[/COLOR]
[I]... continues ...[/I]

I highlighted the resource file syntax in green above. So it's not a matter of "putting processor directives in an .rc file instead of a .h or .cpp file", it's a matter of defining resources using the resource file syntax and (as necessary) using preprocessor directives to conditionally include or exclude blocks of code just like .cpp and .h files do.

If you have Visual Studio Express and need to add resources manually the first thing I would do is read up on the resource file syntax so you can read and write them manually using a text editor. Or you can locate a resource editor from this link in my previous post.

Thanks again for that explanation. I suppose the purpose of that would be to "grab" the file to be bundled, and convert it to binary? That wouldn't need to be language specific, so I do see your point.

The available options for free editing dont seem to inspire confidence. Maybe learning the syntax wouldnt be so bad...
 
Top