Home All Groups Group Topic Archive Search About

1.1 equivalent for Drawing.Icon.ExtractAssociatedIcon?

Author
2 Oct 2006 1:23 PM
Pieter
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

Author
2 Oct 2006 1:55 PM
Dmytro Lapshyn [MVP]
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

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

Show quote
"Pieter" <pieterNOSPAMcoucke@hotmail.com> wrote in message
news:%231kz0Xi5GHA.2536@TK2MSFTNGP06.phx.gbl...
> 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
>
Author
2 Oct 2006 3:06 PM
Pieter
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.)
Author
2 Oct 2006 9:48 PM
Chris Taylor
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

Show quote
"Pieter" <pieterNOSPAMcoucke@hotmail.com> wrote in message
news:%23C%232kRj5GHA.1012@TK2MSFTNGP05.phx.gbl...
> 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.)
>
>
Author
3 Oct 2006 7:35 AM
Pieter
ok thanks for the hint!
Author
3 Oct 2006 5:15 PM
Chris Taylor
Hi,

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

Hope this helps

Show quote
"Pieter" <pieterNOSPAMcoucke@hotmail.com> wrote in message
news:%23K8Ow5r5GHA.1244@TK2MSFTNGP03.phx.gbl...
> ok thanks for the hint!
>
Author
3 Oct 2006 5:31 PM
Chris Taylor
Oops sorry, wrong thread

Show quote
"Chris Taylor" <chris_taylor***@hotmail.com> wrote in message
news:uW3OG%23w5GHA.3452@TK2MSFTNGP05.phx.gbl...
> Hi,
>
> I did a quick google search and came up with this.
> http://www.codeproject.com/system/winlogon_notification_package.asp
>
> Hope this helps
>
> --
> Chris Taylor
> http://dotnetjunkies.com/weblog/chris.taylor
> "Pieter" <pieterNOSPAMcoucke@hotmail.com> wrote in message
> news:%23K8Ow5r5GHA.1244@TK2MSFTNGP03.phx.gbl...
>> ok thanks for the hint!
>>
>
>

AddThis Social Bookmark Button