Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2006

Tip: Looking for answers? Try searching our database.

1.1 equivalent for Drawing.Icon.ExtractAssociatedIcon?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pieter - 02 Oct 2006 14:23 GMT
Hi,

I need to have the icon of the assembly that is calling my Control.Library.
Using 2.0 Framework the "Drawing.Icon.ExtractAssociatedIcon" does the trick.
But this fucntion doesn't exist in the .NET 1.1 Framework, and my control
Library must be able to be compiled in 1.1 too.

Does anybody knows the solution?

thanks a lot in advance,

Pieter
Dmytro Lapshyn [MVP] - 02 Oct 2006 14:55 GMT
Hi,

Create a P/Invoke declaration for the ExtractIcon API function, then use
Icon.FromHandle and pass the handle ExtractIcon returned as the parameter.

Ready-made P/Invoke declaration can be found here:

http://www.pinvoke.net/default.aspx/shell32/ExtractIcon.html

Signature

Regards,
Dmytro Lapshyn [MVP]
http://blogs.vbcity.com/DmytroL

> Hi,
>
[quoted text clipped - 9 lines]
>
> Pieter
Pieter - 02 Oct 2006 16:06 GMT
Ok thanks!

This worked for me:

Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal
hInst As Integer, ByVal lpszExeFileName As String, ByVal nIconIndex As
Integer) As IntPtr
Dim ico As Icon

Dim hIcon As IntPtr ' handle to the icon once it is extracted

hIcon =
ExtractIcon(Microsoft.VisualBasic.Compatibility.VB6.GetHInstance.ToInt32,
ConfigParentAssembly.Location, 0)

ico = Icon.FromHandle(hIcon)

m_ConfigIcon = New Icon(ico, New Size(16, 16))

(ConfigParentAssembly is the System.Reflection.assembly which is calling the
dll, and m_ConfigIcon an Icon-variable.)
Chris Taylor - 02 Oct 2006 22:48 GMT
Hi,

One thing to note. When you use FromHandle, the new Icon instance does not
take ownership of the
handle. This means that when the Icon instance is disposed the handle is not
released, resulting in a resource leak.

You need to call DestroyIcon on the original handle, this will of course
invalidate the icon handle referenced by the Icon instance, so what you need
to do is first clone the icon which will create a new Icon instance which
owns the new Icon handle, allowing you to free the original handle.

ico = Icon.FromHandle(hIcon).Clone();
DestroyIcon(hIcon); // You need to pinvoke DestroyIcon.

Hope this helps

Signature

Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor

> Ok thanks!
>
[quoted text clipped - 17 lines]
> (ConfigParentAssembly is the System.Reflection.assembly which is calling
> the dll, and m_ConfigIcon an Icon-variable.)
Pieter - 03 Oct 2006 08:35 GMT
ok thanks for the hint!
Chris Taylor - 03 Oct 2006 18:15 GMT
Hi,

I did a quick google search and came up with this.
http://www.codeproject.com/system/winlogon_notification_package.asp

Hope this helps

Signature

Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor

> ok thanks for the hint!
Chris Taylor - 03 Oct 2006 18:31 GMT
Oops sorry, wrong thread

Signature

Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor

> Hi,
>
[quoted text clipped - 4 lines]
>
>> ok thanks for the hint!

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.