Solved

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

Posted on 2003-12-10
7
1,152 Views
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!!!!!
mary
0
Comment
Question by:maryTa
  • 2
  • 2
7 Comments
 

Expert Comment

by:stzizza
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
0
 

Author Comment

by:maryTa
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
0
 

Expert Comment

by:stzizza
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.

Scott
0
 

Author Comment

by:maryTa
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:
notifyIcon.Modify(hIcon);

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
0
 
LVL 2

Accepted Solution

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mergeTwo  challenge 13 84
groupNoAdj 7 86
Basic Java Case or If-Else statement... 3 43
T-SQL:  Sigh---Boy, this is fun.... 12 32
This is an explanation of a simple data model to help parse a JSON feed
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.
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…
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…

911 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

17 Experts available now in Live!

Get 1:1 Help Now