简体   繁体   中英

Concatenate String in resource file and pass it to menu item string (winapi) c++

I am writing a win32 application using winapi and i want to concatenate a string in my resource file and give the stirng to my menuitem as the string it should show. when i want to give it to a control it works like a charm, but when i want to use it for the menuItem i get an error message. this might me because the preprocessor does not see the concatination as a string?

does anybody have a clue or idea what i could try? there were simillar post i tried to follow - but it gives me the same result...

other posts on so:

Concatenate string and constant in resource file in C++ (MFC)

Concate define and string in resources

C/C++ Macro string concatenation

as i followed these answeres, i got "ID_ABOUT_STR" as my output instead of the value of it most of the times... and else i got the error...

i hope the question is clear and thank you in advance for the effort :)

.rc File:

IDR_MENU1 MENU
BEGIN
    POPUP L"System"
    BEGIN
        MENUITEM ID_EXIT_STR, ID_SYSTEM_EXIT
        MENUITEM SEPARATOR
        MENUITEM ID_ABOUT_STR, ID_SYSTEM_ABOUT //here i want to give it the ID_ABOUT_STR which is in the resource file... 
    END
END

resource.h : VER_PRODUCTNAME_STR and the other one just contain strings aswell

#define ID_ABOUT_STR                 L"About" VER_PRODUCTNAME_STR L" " VER_FILE_DESCRIPTION_STR

This is the error i get:

Error       RC2122  unknown menu subtype                PRO-PRODUCITON      C:\XXX.rc       195 
Error       RC2125  expected ID value for menu item     PRO-PRODUCITON      C:\XXX.rc       195 

The problem is the L extension from my point of view. The code should compile without the L"..." prefix.

And as your links show, this macros work without problems in the RC compiler

#define CONCAT(a,b) a##b
#define STRINGIZE_(x) #x
#define STRINGIZE(x) STRINGIZE_(x)

As a sample this works for a caption in a dialog

CAPTION STRINGIZE(CONCAT(Concat,Title))

But they don't use the L"..." prefix

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM