Concatenate string and constant in resource file in C++ (MFC)(在 C++ (MFC) 中连接资源文件中的字符串和常量)
问题描述
我有一个带有 MFC 和资源文件的 C++ 项目.在我的 About-Dialog 中,我想添加一个包含程序版本的常量.
I have a C++ project with MFC and a resource file. In my About-Dialog I want to add a constant which contains the version of the programm.
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
如果它看起来像这样,我会收到错误
If it looks like this I get an error
1>srcmonitor.rc(80): error RC2116: expecting number for ID
1>srcmonitor.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>srcmonitor.rc(80): error RC2237: numeric value expected at 3.1.4.1
我的下一个尝试是像我在 rc-file
顶部定义的函数一样调用它,但错误类似于上述两者.
My next try was to call it like a function which I defined at the top of my rc-file
but the error was like the both above.
是否可以在 LTEXT 内的 rc 文件中连接字符串和变量?
Is it possible to concatenate a string and a variable in a rc-file within a LTEXT?
推荐答案
#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 上运行.
Works on VS2013. Should work on VS2010, too.
这篇关于在 C++ (MFC) 中连接资源文件中的字符串和常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C++ (MFC) 中连接资源文件中的字符串和常量
基础教程推荐
- Windows Media Foundation 录制音频 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01