How-to Custom icon for library function window?

Have a library (.lib) project, included a resource and an icon but its never found by the icon look up functions.

IF i use the same resource # as the main executable, I can look up its icon, and set it.

I want to load a custom icon from the library, not the application calling the library. The load always fails (returns NULL). So it appears that libraries cannot have their own resources? Interesting that Visual Studio allows it.

Plan B is to create an icon the hard way, from some binary data in my c++ program. But the "CreateIcon()" function as documented only does monochrome icons. A contradiction there is that it accepts "bits per pixel" arguments,
but appears to only actually work if the number is set to 1? MesS!

So how do i load or create a custom COLOR icon (HICON handle)
from a library that may be used by lots of applications,
so does not "know" the applications resources and vice versa.
It does not appear there is a way to specify which resource source I'm
talking about. The documentation only acknowledges looking up resources based on executable (or dll's)

I expect resource load is a dead end. Anyone know how to create a color icon from C++ code? I would dump my icon file to hex, then use that in c++ to make the HICON. How to create a color icon from data?

1
2
3
4
5
6
7
// none of these work to load an icon from a resource file/icon from a .lib
HICON hIcon = AtlLoadIconImage ( IDI_ESLICON, LR_DEFAULTCOLOR, 0, 0);
or            ::LoadImage(0, MAKEINTRESOURCE(IDI_ESLICON), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT);
or            LoadIcon(0, MAKEINTRESOURCE(IDI_ESLICON));

		SetIcon(hIcon, true);
		SetIcon(hIcon, false);
LoadImage can load a image from a file. So dump the icon content to a temporary file, then load it. Use CAtlTemporaryFile class. I didn't know if there is a way to load an icon from memory using IStream constructor of CImage class.
Topic archived. No new replies allowed.