473,395 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

1.1 equivalent for Drawing.Icon.ExtractAssociatedIcon?

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
Oct 2 '06 #1
6 1926
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/...tractIcon.html

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

"Pieter" <pi****************@hotmail.comwrote in message
news:%2****************@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
Oct 2 '06 #2
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.VB 6.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.)
Oct 2 '06 #3
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

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Pieter" <pi****************@hotmail.comwrote in message
news:%2******************@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.VB 6.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.)


Oct 2 '06 #4
ok thanks for the hint!
Oct 3 '06 #5
Hi,

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

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Pieter" <pi****************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
ok thanks for the hint!

Oct 3 '06 #6
Oops sorry, wrong thread

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Chris Taylor" <ch*************@hotmail.comwrote in message
news:uW****************@TK2MSFTNGP05.phx.gbl...
Hi,

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

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Pieter" <pi****************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>ok thanks for the hint!


Oct 3 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: WALDO | last post by:
I have an interesting quandary. I have developed a program in VB.Net to extract an icon resource from an exe/dll or from an ico file and enumerate its formats (16x16,256 color;32x32,true...
2
by: Alexander VS | last post by:
Hello all! How can i exract an icon associated with a file? I found API function ExtractAssociatedIcon, but can i use this function with VB.Net? Can i do it easier with some .Net class? Thanks.
2
by: active | last post by:
I find Bitmap.Save works for WMF files but Bitmap.FromFile does not. If I use FromFile on a WMF file that came with VS I get an exception. If I use it on a WMF file created with Bitmap.Save I...
4
by: Sin Jeong-hun | last post by:
I already found that I have to use SHGetFileInfo to get the System's associated icon with that file. But what about I just want to get associated icon for some specific extensions? For example,...
6
by: Pieter | last post by:
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...
0
by: Mark | last post by:
Hi Folks (VS .NET 2005 on Windows XP...) I'm using Drawing.Icon.ExtractAssociatedIcon to extract the icon from a filepath etc. to be added to an imagelist used by a treeview. Everything...
0
by: Mark | last post by:
Hi I tried to find a solution to this a while back and more surfing today has yielded nothing usefull. I am using "extractAssociatedIcon" to get icons for a listview containing files etc....
5
by: =?Utf-8?B?TG9hbldvbGY=?= | last post by:
I'm working on a Windows Explorer-like application. What is the best way to find out what application is set to open a particular type of file? Is there a function to do this? Do I have to go...
6
by: Laurent Navarro | last post by:
Hello, I have an EXE (.NET assembly) file with an icon which has 8 formats (128x128, 96x961, ..., 24x24 and 16x16). I would like the extract the 128x128 sized icon only to display it on a...
2
by: Matt | last post by:
How do I get a Icon for display in a list view from just the file extension? If I have a file that exists on a local machine I can use Icon.ExtractAssociatedIcon, but in this case the files are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.