.rc 中添加的位图文件未在 resources.h 中列出
我在资源视图(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只是将文件拖到资源视图上,它只会打开位图进行编辑。
因此,您必须导入它们,然后您会将它们称为
IDB_BITMAPn
要清理它,请关闭资源视图,然后在查看代码模式下打开 .rc 文件,找到包含新位图的部分并找到新位图,如下所示:
现在编写一个正则表达式来将文件名替换为定义,而且我们还需要替换resource.h中的数字部分。
为了使这更简单,请复制上述部分。
因此,第一部分可以使用此 Visual Studio 替换正则表达式来完成,您需要在选定区域上运行它,
这将使其看起来像这样,
然后您想要进行垂直选择(按住 ATL 键,同时按住鼠标)然后将所有 IDB_pictureX 单词按到上方(C# 键盘映射 CTRL+SHIFT+U)
现在将新 IDB_X 映射到旧值。我们可以使用 sed 来完成这项工作,或者制作一个重新映射文件。
后者是通过使用原始 .rc 部分的副本来完成的,并将此替换正则表达式应用于所选区域。
给你这个代码块,如下所示:
你可以执行相同的 ALT+select 将定义更改为大写,给出这个代码,你可以将其放入头文件中的某个位置:
现在一个更干净的解决方案是构建一个sed 命令文件,然后针对您的 resources.h 运行它,您可以这样做
给出:
将该输出复制到文件中,并将其与 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:
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
this will make it look like this
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.
giving you this block of code looking like below:
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:
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
giving:
copy that output into a file, and use that with the sed -F flag