Getting a handle to an icon

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good Morning
Does anyone know how to get a handle to an icon?

I am trying to use the notification API to display a messagebubble and icon to the user. I am using C#
I am able to display the messagebubble using ShNotificationAdd and the appropriate data structure. I am unable to determine how to display an icon along with the messagebubble. I understand that a handle to an icon cast to IntPtr is required in the structure, I am unsure how to get an handle to an icon!! Anyone have some example code on how that is done??

Thanks
Ron
 
It is not possible to get a native hIcon from a managed System.Drawing.Icon
object.

The workaround we use in our NotifyIcon class is to use ExtractIconEx to get
a hIcon of the current application executables default icon:-
hIcon =
ExtractIconEx(System.Reflection.Assembly.GetCallingAssembly().GetName().CodeBase,
0, 0, ref hIcon, 1);

[DllImport("coredll", EntryPoint="ExtractIconEx", SetLastError=true)]
private extern static IntPtr ExtractIconEx(string lpszFile, int hIconIndex,
int hiconLarge, ref IntPtr hIcon, uint nIcons);

It is possible to use native icon resources from any exe or dll in this way.
Be aware however that icons added as resources to your .NETCF executable are
not stored as native icons - you will need to use a native resource editor
to package them. Windows CE does not include a method to load icons from an
ico file.

You may also find Alex's article on Icons useful, it concentrates on
building a managed icon from a hIcon but discusses the structure of an icon.
http://www.opennetcf.org/PermaLink.aspx?guid=342bde3d-eeba-4d78-9748-29eb89ee13bf

Peter
 
Back
Top