连接资源中的定义和字符串 [英] Concate define and string in resources

查看:91
本文介绍了连接资源中的定义和字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个资源文件,需要在其中创建带有连接宏和字符串的字符串定义,诸如此类

I have a resource file where needed create string define with concatenation macros and string, 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" 

但需要简单的"HelloWord",且不带平均引号.

but needed simple "HelloWord" without average quotes.

推荐答案

对于任何关心的人:.rc文件是MFC项目中的资源文件,它定义了UI元素,例如对话框布局.它使用与C ++相同的预处理器,但不共享C ++的语法-在窗口CAPTION字段中,两个字符串文字不能仅仅通过并置来连接.在字符串文字中,两个双引号实际上是一个转义序列,它生成一个双引号字符.所以字面意思:

For anyone who cares: a .rc file is a resource file from an MFC project that defines UI elements, such as dialog layouts. It uses the same preprocessor as C++, but it does not share C++'s syntax -- and in a window CAPTION field, two string literals won't concatenate by just juxtaposing them. Within a string literal, two double quotes is actually an escape sequence that generates one double quote character. So the literal:

"Hello""World"

最终看起来像

Hello"World

在对话框窗口的标题中.

In your dialog Window's caption.

给出的示例的问题:

CAPTION "Hello"STRINGIZE(Word_)

是否必须删除"Hello"末尾的双引号,但是预处理器无法执行此操作. 但是,如果允许在宏中包含"Hello",则可以进行串联.首先,我定义了这些宏:

Is 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 a 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 record:

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

这样,对话框的标题看起来就像 HelloWorld 一样-没有任何引号或其他内容. 希望您可以使用这种技术.

With this, the dialog's caption ends up looking like HelloWorld -- no stray quotes or anything. I hope you can use this technique.

这篇关于连接资源中的定义和字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆