MFC静态库和外部rc(资源)文件图标加载问题
我在主应用程序中从外部资源文件加载图标时遇到问题。我将尝试解释现在如何设置应用程序。主应用程序的资源包括外部对话框*.rc和相应的*.h。链接器包括位于外部静态库 *.lib 中的对话框实现 (CDialog/CFormView)。
外部 *.rc 具有:
IDI_MY_ICON ICON "my_icon.ico"
外部 *.h 具有:
#define IDI_MY_ICON 10000
静态库 *.cpp 中的对话框实现具有:
HICON MyDialog::GetNeededIcon()
{
return AfxGetApp()->LoadIcon(IDI_MY_ICON);
}
我认为它应该与外部 *.rc 文件位于同一文件夹中。我还尝试将它们放在主应用程序文件夹中,但应用程序仍然不加载它们。有人可以解释一下在哪里搜索 my_icon.ico 吗?
PS - 文件内容仅是示例。
I have a problem with loading icons from external resource files in main application. I'll try to explain how application is set right now. The resources of the main application includes external dialog *.rc and appropriate *.h. And linker includes dialog implementation (CDialog/CFormView) which resides in external static library *.lib.
External *.rc has:
IDI_MY_ICON ICON "my_icon.ico"
External *.h has:
#define IDI_MY_ICON 10000
Dialog implementation in static lib *.cpp has:
HICON MyDialog::GetNeededIcon()
{
return AfxGetApp()->LoadIcon(IDI_MY_ICON);
}
I thought that it should reside in the same folder as external *.rc file is. I also tried to place them in the main app folder, but application still doesn't load them. Could someone explain me where my_icon.ico is searched in?
P.S. - Contents of files are only examples here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AfxGetApp()->LoadIcon(IDI_MY_ICON);
尝试从当前应用程序 (exe) 加载图标。如果你想从另一个模块加载它,你要么必须记住从 LoadLibrary 返回的句柄,要么调用 GetModuleHandle 再次检索它。
AfxGetApp()->LoadIcon(IDI_MY_ICON);
tries to load the icon from the current app (exe).If you want to load it from another module, you will either have to remember the handle returned from LoadLibrary, or call GetModuleHandle to retrieve it again.
您的 .rc 文件由 rc.exe 编译以将图标嵌入到可执行文件中。 rc.exe 使用包含路径来查找资源。这是通过 INCLUDE 环境变量或使用 rc.exe 的 /I 选项指定的。如果“my_icon.ico”不起作用,请尝试移动文件或更改包含路径。
说明:
rc.exe 将 .rc 文件编译为 .res,但它的链接器实际嵌入到可执行文件中。
Your .rc file is compiled by rc.exe to embed the icon in your executable. rc.exe uses the include path to find the resources. This is specified by either the INCLUDE environment variable or by using /I option to rc.exe. If "my_icon.ico" doesn't work, try moving the file or change the include path.
Clarification:
rc.exe compiles .rc files into .res, but its the linker that does the actual embedding into the executable.