Specific definition and string in resources

I have a resource file where you need to create a string definition using concatenation macros and strings, something like this

#define _STRINGIZE(n) #n #define STRINGIZE(n) _STRINGIZE(n) #define Word_ Word 100 DIALOGEX 0, 0, 172, 118 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Hello"STRINGIZE(Word_)=>"Hello"Word" 

but for a simple "HelloWord" without simple quotes, you need a simple

+4
source share
1 answer

For anyone who cares: the .rc file is a resource file from an MFC project that defines user interface elements such as dialog layouts. It uses the same preprocessor as C ++, but does not support C ++ syntax - and in the window's CAPTION field, two string literals are not combined, just matching them. Inside a string literal, two double quotes are actually an escape sequence that generates a single double quote character. So literally:

 "Hello""World" 

looks like

 Hello"World 

In the dialog box Window.

The problem with the above example:

 CAPTION "Hello"STRINGIZE(Word_) 

This means that the double quote at the end of "Hello" must be removed, but the preprocessor cannot do this. However, if "Hello" is allowed to be included in the macro, concatenation is possible. First I defined these macros:

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

then inside the dialog entry:

  ... EXSTYLE WS_EX_APPWINDOW CAPTION STRINGIZE(CONCAT(Hello,World)) FONT 10, "Segoe UI Semibold", 600, 0, 0x0 ... 

In this case, the title of the dialog box looks like HelloWorld - without any stray quotes or anything else. Hope you can use this technique.

+4
source

Source: https://habr.com/ru/post/1436771/


All Articles