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

The listview icon (16*16) color is no 32bit using ExtractIcon with imagelist

14 views
Skip to first unread message

yxq

unread,
Dec 18, 2009, 7:33:51 AM12/18/09
to
Application.EnableVisualStyles()
Imagelist.ColorDepth = ColorDepth.Depth32Bit
But the icon seem no 32bit, the color is not full, it's ugly, why?


Herfried K. Wagner [MVP]

unread,
Dec 18, 2009, 9:25:39 PM12/18/09
to

Kindly post the code you use to extract the icon and to add it to the
image list.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

yxq

unread,
Dec 19, 2009, 1:32:24 AM12/19/09
to
The code is below, thank you.
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA"
(ByVal hInst As IntPtr, ByVal lpszExeFileName As String, ByVal nIconIndex As
Integer) As IntPtr

Public Function ExtractIcons(ByVal iconfile As String, ByVal iconindex As
Int32) As Icon
Try
Dim hIcon As IntPtr
hIcon =
ExtractIcon(System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)),
iconfile, iconindex)
Return Icon.FromHandle(hIcon)
Catch ex As Exception
End Try
Return Nothing
End Function

Application.EnableVisualStyles()
............................
Imagelist.ColorDepth = ColorDepth.Depth32Bit
Dim ListViewItem As ListViewItem = New ListViewItem("Test")
ListView1.Items.Add(ListViewItem)
Dim tempIcon As Icon = ExtractIcons("c:\test.exe", 0)
If Not tempIcon Is Nothing Then
ImageList1.Images.Add(tempIcon)
ListViewItem.ImageIndex = ImageList1.Images.Count - 1
End If

"Herfried K. Wagner [MVP]" <hirf-spa...@gmx.at>
OD45IKFg...@TK2MSFTNGP05.phx.gbl...

Armin Zingler

unread,
Dec 19, 2009, 7:11:25 AM12/19/09
to
yxq schrieb:

> The code is below, thank you.
> ////////////////////////////////////////////////////////////////////////////////////////////////////////////
> Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA"
> (ByVal hInst As IntPtr, ByVal lpszExeFileName As String, ByVal nIconIndex As
> Integer) As IntPtr
>
> Public Function ExtractIcons(ByVal iconfile As String, ByVal iconindex As
> Int32) As Icon
> Try
> Dim hIcon As IntPtr
> hIcon =
> ExtractIcon(System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)),
> iconfile, iconindex)

I guess it's not the problem, but according to the documentation of the ExtractIcon function,
the first argument must be NULL (Intptr.Zero).


Also have a look at the Icon.ExtractAssociatedIcon function.


--
Armin

0 new messages