开发者

MFC static library and external rc(resource) file icon loading problem

开发者 https://www.devze.com 2023-02-18 14:44 出处:网络
I have a problem with loading icons from external resource files in main application. I\'ll try to explain how application开发者_如何学C is set right now. The resources of the main application include

I have a problem with loading icons from external resource files in main application. I'll try to explain how application开发者_如何学C 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消