visual-studio Visual Studio 2005. RC 文件包括

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/95361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:32:22  来源:igfitidea点击:

Visual Studio 2005. RC File includes

visual-studiovisual-studio-2005

提问by

I'm programming in C++ on Visual Studio 2005. My question deals with .rc files. You can manually place include directives like (#include "blah.h"), at the top of an .rc file. But that's bad news since the first time someone opens the .rc file in the resource editor, it gets overwritten. I know there is a place to make these defines so that they don't get trashed but I can't find it and googling hasn't helped. Anyone know?

我在 Visual Studio 2005 上用 C++ 编程。我的问题涉及 .rc 文件。您可以在 .rc 文件的顶部手动放置像 (#include "blah.h") 这样的包含指令。但这是个坏消息,因为有人第一次在资源编辑器中打开 .rc 文件时,它会被覆盖。我知道有一个地方可以定义这些定义,这样它们就不会被破坏,但我找不到它,谷歌搜索也没有帮助。有人知道吗?

采纳答案by dgvid

Add your #include to the file in the normal way, but also add it to one the three "TEXTINCLUDE" sections in the file, like so:

以正常方式将 #include 添加到文件中,但也将其添加到文件中的三个“TEXTINCLUDE”部分之一,如下所示:

2 TEXTINCLUDE
BEGIN
    "#include ""windows.h""\r\n"
     "#include ""blah.h\r\n"
     "
#ifdef WIN64
#include "Icons64.rc"
#else
#include "Icons32.rc"
#endif
" END

Note the following details:

请注意以下详细信息:

  • Each line is contained in quotes
  • Use pairs of quotes, e.g., "" to place a quote character inline
  • End each line with \r\n
  • End the TEXTINCLUDE block with "\0"
  • 每行都包含在引号中
  • 使用引号对,例如,"" 来放置一个内联的引号字符
  • 用 \r\n 结束每一行
  • 以“\0”结束 TEXTINCLUDE 块

Statements placed in the "1 TEXTINCLUDE" block will be written to the beginning of the .rc file when the file is re-written by the resource editor. Statements placed in the 2 and 3 blocks follow, so you can guarantee relative include file order by using the appropriately numbered block.

当资源编辑器重新编写文件时,放置在“1 TEXTINCLUDE”块中的语句将写入 .rc 文件的开头。放置在 2 和 3 块中的语句紧随其后,因此您可以通过使用适当编号的块来保证相对的包含文件顺序。

If your existing rc file does not already include TEXTINCLUDE blocks, use the new file wizard from the Solution Explorer pane to add a new rc file, then use that as a template.

如果您现有的 rc 文件尚未包含 TEXTINCLUDE 块,请使用“解决方案资源管理器”窗格中的新文件向导添加新的 rc 文件,然后将其用作模板。

回答by Chris

回答by Andrei Belogortseff

Within Visual Studio IDE, right-click on the .rc file (in the Resource View panel), and select "Resource includes" from the shortcut menu. When the dialog opens, use its "Compile-time directives" area to enter whatever you want to include in the .rc file. For example, if you want your 64-bit and 32-bit builds to use different icons, you could include the appropriate resource file for each build as follows:

在 Visual Studio IDE 中,右键单击 .rc 文件(在“资源视图”面板中),然后从快捷菜单中选择“资源包括”。当对话框打开时,使用其“编译时指令”区域输入您想要包含在 .rc 文件中的任何内容。例如,如果您希望 64 位和 32 位构建使用不同的图标,您可以为每个构建包含适当的资源文件,如下所示:

##代码##

It's worth noting that these defines are not set in the resource compiler by default, so for your 64 bit build make sure you add /DWIN64 to the rc build.

值得注意的是,默认情况下,这些定义未在资源编译器中设置,因此对于您的 64 位构建,请确保将 /DWIN64 添加到 rc 构建中。

回答by Ron Pihlgren

All the gory details can be found in MFC Technote #35.

所有血腥细节都可以在MFC 技术说明 #35 中找到

-Ron

-罗恩

回答by Herms

I'm not completely sure why you're trying to do, but modifying the resource files manually probably isn't a good idea.

我不完全确定您为什么要这样做,但是手动修改资源文件可能不是一个好主意。

I believe general practice for VC++ for globally-accessible values is to define them in stdafx.h (at least that's how I've seen it done), or to create something like a "globals.h" header file and include that wherever you need it. It really depends on what you're trying to accomplish though.

我相信 VC++ 的全局可访问值的一般做法是在 stdafx.h 中定义它们(至少我是这样看到的),或者创建类似“globals.h”的头文件并将其包含在任何地方需要它。不过,这实际上取决于您要实现的目标。