【问题标题】:Concatenate string and constant in resource file in C++ (MFC)在 C++ (MFC) 中连接资源文件中的字符串和常量
【发布时间】:2016-05-05 14:40:03
【问题描述】:

我有一个带有 MFC 和资源文件的 C++ 项目。在我的 About-Dialog 中,我想添加一个包含程序版本的常量。

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

如果它看起来像这样,我会收到错误

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

我还尝试将它与+ 连接起来

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

但我得到了错误

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

我的下一个尝试是像我在rc-file 顶部定义的函数一样调用它,但错误类似于上述两者。

是否可以在 LTEXT 内的 rc 文件中连接字符串和变量?

【问题讨论】:

  • 请显示monitor.rc第80行周围的行。
  • 忘记我之前的评论。你不能做这个。动态显示版本。这需要您的 About 对话框的 OnitiDialog 函数中的 3-4 行代码。
  • @MichaelWalz 谢谢你的回答。我在我的 OnInitDialog 函数中实现了它

标签: c++ visual-studio-2010 mfc resource-file


【解决方案1】:
#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 ) )

适用于 VS2013。应该也可以在 VS2010 上运行。

【讨论】:

  • 包含双下划线的符号,或以下划线后跟大写字母开头的符号(或在全局范围内以下划线开头的符号)保留供实现使用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-06
  • 1970-01-01
  • 1970-01-01
  • 2014-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多