Get Windows Handle for Icon Object in c# for WIN CE

Posted on 2003-12-10
Medium Priority
Last Modified: 2007-12-19
Hello everybody!

I try to change my NotifyIcon in Taskbar for some reasons. (on an Ipaq --> Win CE 3.0, .Net ,c#)
So I have another icon included in my project as an embedded resource.
And I load it into an Icon Object.
In the .Net Framework you get the Windows handle simply using this command: "Icon.Handle".
But this is not supported In the Compact Framework.

I need the Handle for my Function notifyicon.modify(hicon);
(IntPtr hicon= handle to the new Icon)

Any hints ideas ore something like that?
Thank you very much!!!!!
Question by:maryTa
  • 2
  • 2

Expert Comment

ID: 9914759
If you know the name of the resource try "FindResource(HMODULE hModule, LPCWSTR lpName, LPCWSTR lpType)" or "LoadIcon(HINSTANCE hInstance, LPCSTR lpIconName)"
Both of these functions work on CE/pocket pc 1.0 and later.

(For find resource API)
Types are as follows:
RT_ACCELERATOR Accelerator table
RT_BITMAP Bitmap resource
RT_CURSOR Hardware-dependent cursor resource
RT_DIALOG Dialog box
RT_FONT Font resource
RT_FONTDIR Font directory resource
RT_GROUP_CURSOR Hardware-independent cursor resource
RT_GROUP_ICON Hardware-independent icon resource
RT_ICON Hardware-dependent icon resource
RT_MENU Menu resource
RT_MESSAGETABLE Message-table entry
RT_RCDATA Application-defined resource (raw data)
RT_STRING String-table entry
RT_VERSION Version resource

Author Comment

ID: 9927058
Thank you for that hint, but I tried these functions already, with no success. For FindRessource I get the Error 1814 (Ressource not found) and the loadicon funktion needs an ID I don´t have as the lpname. for example:
My Icon I already have has the id "#32512" as lpname.
with IntPtr hIcon=LoadIcon(GetmoduleHandle(null),"#32512");
I get my Handle of my Application Icon.
"#32512"  is the ID I can find using an Resource-Explorer for my app.exe.
But all the other Icons I´ve included in the project are not visible in the explorer and I´ve no idea why....
(LoadIcon(GetModuleHandle(null),"resource1"); or "notify3.ico" or "notify3" failes and returns zero)
So on the one hand I simply need a way to identify my embedded Icons (integer resource id), or on the other I need another way to get the Icons handle, OR I need a way to change my ApplicationIcon in the code. (I added the applicationIcon in the Project Settings>Application Icon)
Maybe, the way could be to store the icons in a dll. I can try to use FindResource correctly......
Any further ideas? Or sample Code ?
Thank you a lot so far, and hope for any other input!!!!
ciaoi mary

Expert Comment

ID: 9930764
Mary did you try:
HICON hIcon :=  LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(32512)); to see if it returns the same error
Second did you check the rc file to see hoe they are being included, they may be getting included as RC_DATA.
Also, when you are using the Icon class how are you loading the icon, because the only constructor the .Net compact framework supports is
public Icon(Stream stream); in which the icon class be loaded from a stream. I hope this helps a little.


Author Comment

ID: 10340395
Please close mx question because I found the answer last week.

My Problem was not how to display an Icon, but how to get the resource-ID to change it while running the program.

The only possibility to chance the Icon on Taskbar is:
//to get the handle:
hIcon=LoadIcon(GetModuleHandle(null),"#101"); //or which number you want
//to change the Icon:

To include more than one Icon into the Exe (except the Application-Icon) you have to open the compiled Exe file in Visual Studio .Net 2003. You can See a folder "icon". When you open it you can see the Application-Icon with its Resource-ID 32512. Now you can right-click on the folder to add more Resources. Then you choose, Icon and click "import". Your new Icon displays in this folder with the ID 101. You can modify the IDs, but keep in mind, that you have to use the right number in the code.
If you recompile your application you lost this Icon and have to add it again this way.
With these Icons you can now chance the Icon or animate it on Taskbar.

I hope this will help people with similar problems.
Thanks for your comments.
ciaoi Mary

Accepted Solution

Lunchy earned 0 total points
ID: 10374151
Closed, 65 points refunded.
Friendly Neighbourhood Community Support Admin

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Simple Linear Regression

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question