.rc 中添加的位图文件未在 resources.h 中列出

发布于 2024-08-28 05:35:46 字数 214 浏览 5 评论 0原文

我在资源视图(Visual Studio)中向我的 MFC 项目添加了大量位图文件。但是,resource.h 文件未列出任何这些文件。我希望它们以与 .rc 位图列表中添加的名称完全相同的名称列出(假设名称是 xxx) 我希望将其列为 #define IDB_xxx 如果我尝试单击 .rc 列表中的位图并将其导入,它将被列为 IDB_BITMAP1。由于文件数量巨大,我无法手动重命名它们以在我的代码中使用。

I added a large number of bitmap files to my MFC project in resource view (Visual Studio). However, the resource.h file does not list any of these files. I would want them to be listed with exactly the same name as they are added in .rc bitmap list (say the name is xxx)
I want it listed as #define IDB_xxx
If I try to click on the bitmap in the .rc list and import it, it gets listed as IDB_BITMAP1. Owing to the large number of files it is not feasible for me to manually rename them for use in my code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2024-09-04 05:35:46

如果您只是将文件拖到资源视图上,它只会打开位图进行编辑。

因此,您必须导入它们,然后您会将它们称为 IDB_BITMAPn

要清理它,请关闭资源视图,然后在查看代码模式下打开 .rc 文件,找到包含新位图的部分并找到新位图,如下所示:

IDB_BITMAP4             BITMAP                  "C:\\picutre1.bmp"
IDB_BITMAP5             BITMAP                  "C:\\picutre2.bmp"
IDB_BITMAP6             BITMAP                  "C:\\picutre3.bmp"

现在编写一个正则表达式来将文件名替换为定义,而且我们还需要替换resource.h中的数字部分。

为了使这更简单,请复制上述部分。

因此,第一部分可以使用此 Visual Studio 替换正则表达式来完成,您需要在选定区域上运行它,

^:i{:b+}BITMAP{:b+}"{.*\\}{.*}.bmp"

IDB_\4\1BITMAP\2"\3\4.bmp"

这将使其看起来像这样,

IDB_picutre1             BITMAP                  "C:\\picutre1.bmp"
IDB_picutre2             BITMAP                  "C:\\picutre2.bmp"
IDB_picutre3             BITMAP                  "C:\\picutre3.bmp"

然后您想要进行垂直选择(按住 ATL 键,同时按住鼠标)然后将所有 IDB_pictureX 单词按到上方(C# 键盘映射 CTRL+SHIFT+U)

现在将新 IDB_X 映射到旧值。我们可以使用 sed 来完成这项工作,或者制作一个重新映射文​​件。

后者是通过使用原始 .rc 部分的副本来完成的,并将此替换正则表达式应用于所选区域。

^{:i}:b+BITMAP:b+".*\\{.*}.bmp"

#define IDB_\2\t\t\1

给你这个代码块,如下所示:

#define IDB_picutre1        IDB_BITMAP4
#define IDB_picutre2        IDB_BITMAP5
#define IDB_picutre3        IDB_BITMAP6

你可以执行相同的 ALT+select 将定义更改为大写,给出这个代码,你可以将其放入头文件中的某个位置:

#define IDB_PICUTRE1        IDB_BITMAP4
#define IDB_PICUTRE2        IDB_BITMAP5
#define IDB_PICUTRE3        IDB_BITMAP6

现在一个更干净的解决方案是构建一个sed 命令文件,然后针对您的 resources.h 运行它,您可以这样做

^{:i}:b+BITMAP:b+".*\\{.*}.bmp"

s/\1/IDB_\2/

给出:

s/IDB_BITMAP4/IDB_picutre1/
s/IDB_BITMAP5/IDB_picutre2/
s/IDB_BITMAP6/IDB_picutre3/

将该输出复制到文件中,并将其与 sed -F 标志一起使用

If you just drag the file onto the Resource View, it just open the bitmaps for editing.

So you have to Import them, then you will get them referred to as IDB_BITMAPn

To clean that up close the resource view then open the .rc file in View Code mode, find the section with the new bitmaps and find the new bitmaps like this:

IDB_BITMAP4             BITMAP                  "C:\\picutre1.bmp"
IDB_BITMAP5             BITMAP                  "C:\\picutre2.bmp"
IDB_BITMAP6             BITMAP                  "C:\\picutre3.bmp"

So now write a regex to replace the file name into the define, but also we will need to replace the numbers section in the resource.h also.

To make this easiest, make a copy of the above section.

So the first part can be done with this visual studio replace regex, which you'll want to run over the selected area

^:i{:b+}BITMAP{:b+}"{.*\\}{.*}.bmp"

IDB_\4\1BITMAP\2"\3\4.bmp"

this will make it look like this

IDB_picutre1             BITMAP                  "C:\\picutre1.bmp"
IDB_picutre2             BITMAP                  "C:\\picutre2.bmp"
IDB_picutre3             BITMAP                  "C:\\picutre3.bmp"

you then want to do a vertical selection (hold the ATL key while mousing down) over all the IDB_pictureX words then press to upper (C# keymap CTRL+SHIFT+U)

Now the to map the NEW IDB_X to the old values. We could use sed to do the work, or make a remapping file.

The latter is done by using the copy of the original .rc section, and apply this replace regex over the selected area.

^{:i}:b+BITMAP:b+".*\\{.*}.bmp"

#define IDB_\2\t\t\1

giving you this block of code looking like below:

#define IDB_picutre1        IDB_BITMAP4
#define IDB_picutre2        IDB_BITMAP5
#define IDB_picutre3        IDB_BITMAP6

which you can do the same ALT+select to change to upper case the defines, giving this code which you can place into a header file somewhere:

#define IDB_PICUTRE1        IDB_BITMAP4
#define IDB_PICUTRE2        IDB_BITMAP5
#define IDB_PICUTRE3        IDB_BITMAP6

now a more clean solution would be to build a sed command file, and run that against your resource.h which you can do like this

^{:i}:b+BITMAP:b+".*\\{.*}.bmp"

s/\1/IDB_\2/

giving:

s/IDB_BITMAP4/IDB_picutre1/
s/IDB_BITMAP5/IDB_picutre2/
s/IDB_BITMAP6/IDB_picutre3/

copy that output into a file, and use that with the sed -F flag

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文