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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

832 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