Add icon from file to Windows CE application

I have some custom icons(.ico) I want to load to my Windows CE/Mobile 6 application as it is running. I have tried LoadImage but found since then that LoadImage only works with an HINSTANCE in the first parameter for windows ce. Meaning LoadImage will only load icons from the compilied application and not from an outside source as needed in my case from a file.

I have my files located in a file on the device, e.g. c:\custom\icon1.ico.

I see many folks talk about this on the net but yet to find any example or pointers as to what function(s) are needed to make this work in ce.

I have seen some reference to functions such as SHLoadImageFile, SHGetFileInfo and etc. but have yet been able to get any of the above or others to work.

I will need some working example code to get this problem solved.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hi atom,

found this link and thought it might be helpful.
no official solution was accepted, but you might just try out the suggested options and you might get lucky.
An example:
Loading Images with undocumented API in PPC 2002
If it's from a file, it makes a sense to switch to another format - JPEG, PNG,... if it is about WM 6.1, maybe to add the alpha-blending.
atomicgs12Author Commented:
thanks pqnatyuk -

I've used the SHLoadImageFile but even thought the documentation says it will take ico(icon) files it will not work for me. I can load up bmp images but I need a way to get the ico image loaded. Do you know of a way to convert a loaded bmp file to an ico?
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

I'm sure I used SHLoadImageFile to load the icons.
In order to test your code, I'd try to load the same icon from the application resources. If it will work, I will agree with you.

SHLoadImageFile is a function from Shell API. cab-files, homescreen used icon files for many years and use exactly this Shell API.

I've proposed another way for you - convert the files to other format.

As an option, you can try CxImage:

For test (maybe you lose your icon when you draw it), you can check this code:
Icons in Win32

In the worst case you can make your own function that will load the icons. This way will always work.
This link has the code.
atomicgs12Author Commented:
pqnatyuk -

Your link "" started out sounding like a good idea but after some time porting the code over, once one has the ReadIconFromICOFile then what? How does one get it to an HIMAGE or HICON and display it. I looked further and it has a call MakeIconFromResource but that function uses CreateIconFromResource which is not in CE.

I can load any of my icon from with in my resource/program. So I know they are good.

SHLoadImageFIle does not work
I can get an hicon handle from my file resource with SHGetFIleInfo but when I use SHNotifyIcon to add the icon I get an empty icon display, an icon with the default windows logo.

Any other ideas?
Try to draw the icon in the dialog, or in a static control. For a test.

I posted that link not because of this function that you cannot find, but because I wanted to show you the low-level format of the icon file. There are many examples reading the icon from the file and they do not use any strange API - plain C and simple Win32 that for sure works on CE. CreateIconIndirect creates the icon.

Please do not forget that the icon should have the correct size (SM_CXICON and SM_CYICON system metric values):

This is about Microsoft Windows CE:
Creating Icons, Bitmaps, Images, and Strings
If you decided to take the icon from the resource - it says how to do it.

SHLoadImageFIle? Do you mean SHLoadImageFile? It exists if you have aygshell.

"This function converts files of several types, including GIF (Graphics Interchange Format), PNG (Portable Network Graphics), JPG (Joint Photographic Experts Group), ICO (icon), and BMP (bitmap) file formats. Other image file types may be supported if the correct decoder is installed."


Windows CE .NET 4.0 and later

atomicgs12Author Commented:
"Please do not forget that the icon should have the correct size (SM_CXICON and SM_CYICON system metric values):"
Yes I know the sizes are correct because as I stated before I have taken my 'file' icons placed them in the .rc of the project, built it and the resource icons are displayed.

"This is about Microsoft Windows CE:
Creating Icons, Bitmaps, Images, and Strings
If you decided to take the icon from the resource - it says how to do it."
As I stated in my original request I need to add the icon from a 'FILE". I can do resource icon loading all day long. Loading from a FILE is the problem.

No 'SHLoadImageFIle" does NOT return a handle with GetLastError it returns an error 6 which equals "The handle is invalid. " Look up 'SHGetFileInfo the SHFILEINFOR data will return an icon handle. Only when I place the icon handle in Shell_NotifyIcon it displays a default Windows icon, like an empty icon.

Have you ever used SHell_NotifyIcon.

Yes. On PPC 2003 in 2005.
It works since CE 1.0:

The icon was in the app resources, the size was 16x16, LoadImage loaded that fine.

I used an article from Nancy Nicolaisen. Maybe this one:
Managing Shell Functionality

In the SDK samples you can find TrayApp:

MSDN. Using the Microsoft .NET Compact Framework MessageWindow Class

CodeProject.Adding Icons to the System Tray
atomicgs12Author Commented:
I really appreciate you responding to all my comments but your last message only delt with icons retrieved from resources, nothing abut icons retrieved from files.
I would suggest you create an icon, place it in a file location, run some app you have and try to retrieve and display the icon from the file location at run time in your app. If you can do that then you have solved solution else we are just going in circles. You talking about resource icons and I am talking about file icons.

If you really need to load an icon from the ico-file, you'll do it yourself. I'm trying simply to help. I do not have (and cannot have) any personal interest about this task. I do not need to load any icon from any file right now. If I need I'd put the icon into the app resources. But I prefer to use the png-format everywhere.

Icons and this SHLoadImage is an old story.  I do see in Google now that many people complained about SHLoadImage and ico-format. SHLoadImageFile returns HBITMAP. Icon is a bit different format. But MSDN says that SHLoadImageFile load the icons.

You can try one more way. Here you may find an example.
CodePoject. Display PNG, JPG, etc. on Pocket PC
There is BOOL LoadICO(LPCTSTR lpszFileName) function.

I'd recommend simply switch to any other format if you have the image in an external file.
If you will download the code from that article, you will find CxImage library inside. There is the ICO-decoder in ximaico.cpp. You can use the full library or take only this code from
bool CxImageICO::Decode(CxFile *hFile).
atomicgs12Author Commented:
Still researching this.
how about using ExtractIconEx() and putting icons in dll? otherwise use CxImage library
Occasionally I found this article in MSDN:

There is a code loading the icons from the file.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.