Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-12-10
7
Medium Priority
?
1,208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Six Sigma Control Plans
Starting up a Project

610 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