Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting a handle to an icon

1 view
Skip to first unread message

Peter Foot [MVP]

unread,
Apr 20, 2004, 11:27:12 AM4/20/04
to
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

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

"Ron Jacobs" <rja...@datacaptureintl.com> wrote in message
news:89A35F6A-D186-491D...@microsoft.com...
> 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


0 new messages