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

Posted on 2003-12-10
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
fix34  challenge 9 97
Order table with macro 3 75
Path of Workbook 3 45
creating threads in delphi 1 55
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now