简体   繁体   English

在资源文件中使用宏

[英]Using macros in resource files

I would like to use #define'd strings in my .rc file. 我想在我的.rc文件中使用#define字符串。 For example, say I have #include'd this .h file in my .rc file: 例如,假设我已将.h文件包含在.rc文件中:

#if defined(RED_BUILD)
  #define CAPTION_TEXT "Red Window"
  #define PROMPT_TEXT "Red Prompt"
#else
  #define CAPTION_TEXT "Blue Window"
  #define PROMPT_TEXT "Blue Prompt"
#endif

In my .rc file, say I have the dialog box: 在我的.rc文件中,说我有对话框:

IDD_Dialog DIALOG 0, 0, 286, 258
STYLE WS_POPUP | WS_CAPTION
CAPTION "First " CAPTION_TEXT " Dialog"
BEGIN
  LTEXT "First " PROMPT_TEXT, -1, 4, 80, 120, 8
  LTEXT "Second " PROMPT_TEXT, -1, 4, 90, 120, 8
END

However the resource compiler does not like this, giving a "BEGIN expected in dialog". 但是,资源编译器不喜欢这样,给出了“对话框中需要BEGIN”。 Is there any way I can coax the precompiler to handle this? 有什么办法可以促使预编译器处理此问题?

My current workaround is #if defined(RED_BUILD) in my .rc file, which works, but is not ideal, as I have hundreds of prompts that I need to change. 我当前的解决方法是在.rc文件中#if defined(RED_BUILD)起作用,但并不理想,因为我需要更改数百条提示。

最好的方法是维护不同的资源文件并进行编译,而不是处理一个大的“ ifdef`d”资源文件中的所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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