3

I have a C++ project with MFC and a resource file. In my About-Dialog I want to add a constant which contains the version of the programm.

IDD_ABOUTBOX DIALOG DISCARDABLE  34, 22, 237, 65
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Monitor"
FONT 8, "MS Sans Serif"
BEGIN
    ICON            IDR_MAINFRAME, IDC_STATIC, 11, 22, 20, 20
#ifdef __64BIT__
    LTEXT           "Communication Monitor V" APP_VERSION " x86_64", IDC_STATIC, 40, 13, 150, 8
#else
    LTEXT           "Communication Monitor V" APP_VERSION " x86_32", IDC_STATIC, 40, 13, 150, 8
#endif //__64BIT__
    DEFPUSHBUTTON   "OK", IDOK, 200, 6, 32, 14
END

If it looks like this I get an error

1>src\monitor.rc(80): error RC2116: expecting number for ID
1>src\monitor.rc(80): error RC2108: expected numerical dialog constant

I also tried to concatenate it with a +

IDD_ABOUTBOX DIALOG DISCARDABLE  34, 22, 237, 65
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Monitor"
FONT 8, "MS Sans Serif"
BEGIN
    ICON            IDR_MAINFRAME, IDC_STATIC, 11, 22, 20, 20
#ifdef __64BIT__
    LTEXT           "Communication Monitor V" + APP_VERSION + " x86_64", IDC_STATIC, 40, 13, 150, 8
#else
    LTEXT           "Communication Monitor V" + APP_VERSION + " x86_32", IDC_STATIC, 40, 13, 150, 8
#endif //__64BIT__
    DEFPUSHBUTTON   "OK", IDOK, 200, 6, 32, 14
END

but I get the error

1>src\monitor.rc(80): error RC2237: numeric value expected at 3.1.4.1

My next try was to call it like a function which I defined at the top of my rc-file but the error was like the both above.

Is it possible to concatenate a string and a variable in a rc-file within a LTEXT?

Premox
  • 323
  • 10
  • 25

1 Answers1

3
#define HSTR( N ) #N
#define STR( N ) HSTR( N )
#define VER_TXT( N ) Communication Monitor V##N x86_32
#define VER_STR( N ) STR( VER_TXT( N ) )

Works on VS2013. Should work on VS2010, too.

zdf
  • 4,382
  • 3
  • 18
  • 29
  • Symbols containing a double underscore, or symbols starting with an underscore followed by a capital letter (or symbols starting with an underscore at global scope) are reserved for use by the implementation. – IInspectable Jan 28 '16 at 17:58