|
-
Feb 26th, 2004, 06:39 PM
#1
Thread Starter
Fanatic Member
Ugly icons...[RESOLVED]
Hi.
Have any of you ever tried to extract an icon from a DLL, and show it in a picturebox on WinXP?
The alphablended part of the icon is converted to a solid black.
I found some code on PSC but for some strange reason it only works on icons extracted with SHGetFileInfo API and not the ExtractIconEx API. And of course, I need to use ExtractIconEx because I need to pass an index to the icon I want.
Does anyone know how to restore the alphablend regardless of the API?
Or does anyone know how to specify which icon to extract using SHGetFileInfo?
Last edited by pax; Feb 27th, 2004 at 12:32 PM.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 03:20 AM
#2
Sleep mode
I used "SHGetFileInfo" API to extract an icon from files and yes it gives the same result as you said above . Didn't work much on that but I'm a little happy (for now ) with it . If you need the code , tell me to paste it here . It's a C# class though .
-
Feb 27th, 2004, 03:52 AM
#3
Thread Starter
Fanatic Member
Hi.
So you get the solid black as well?
You said you use SHGetFileInfo?
Do you have a way of specifying the index?
I mean, how can I extract icon no. 123 from shell32.dll using SHGetFileInfo?
Until now I have only been able to extract that using ExtractIconEx.
I only use SHGetFileInfo to get the associated icon.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 05:13 AM
#4
Sleep mode
Originally posted by pax
Hi.
So you get the solid black as well?
You said you use SHGetFileInfo?
Do you have a way of specifying the index?
I mean, how can I extract icon no. 123 from shell32.dll using SHGetFileInfo?
Until now I have only been able to extract that using ExtractIconEx.
I only use SHGetFileInfo to get the associated icon.
Yes , I get that black nasty color around the edges . But I think this because I converted the icon to bitmap .
I mean, how can I extract icon no. 123 from shell32.dll using SHGetFileInfo?
What do you mean by icon number ? and what index is that ?
-
Feb 27th, 2004, 05:22 AM
#5
Thread Starter
Fanatic Member
Hi.
The Shell32.dll file is an icon resource containing some 200 icons.
Index 3 is a closed folder
Index 4 is an open folder
Index 34 is the desktop icon
etc.
etc.
With the ExtractIconEx function you can specify which icon you want to extract. Whereas, as far as I know, the SHGetFileInfo only returns the associated icon.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 05:38 AM
#6
Sleep mode
I didn't know this about Shell32.dll .
and I've just tried "SHGetFileInfo" API with the above file and returned the associated icon which is not what you want .
Hold on, I think I've tried something like this in one of my previous proj . I look it up .
-
Feb 27th, 2004, 06:29 AM
#7
Sleep mode
Sorry , it took me a while to convert this code to .NET (from one of my VB6 progys ) .
ExtractAssociatedIcon API is the one that returns icon with index .
VB Code:
<DllImport("shell32.dll", EntryPoint:="ExtractAssociatedIcon")> _
Private Shared Function ExtractAssociatedIcon(ByVal hInst As System.IntPtr, <MarshalAs(UnmanagedType.LPStr)> ByVal lpIconPath As String, ByRef lpiIcon As Integer) As System.IntPtr
End Function
Dim ico As Icon
Private Sub GetIconInfo()
Dim iconPath As String = "C:\windows\system32\shell32.dll"
Dim hInst As IntPtr = Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly().GetModules()(0))
Dim iIcon As Int32
Dim hIcon As IntPtr
'6 is the index you need to change only .
hIcon = ExtractAssociatedIcon(hInst, iconPath, 6)
ico = Icon.FromHandle(hIcon)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetIconInfo()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.DrawIcon(ico, 0, 0)
End Sub
-
Feb 27th, 2004, 06:35 AM
#8
Thread Starter
Fanatic Member
Wow, thanks.
I only have Win2000 here, so I will try when I get home on WinXP, to see if my AlphaFix function will work on these icons.
If it does I will post the alphafix solution.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 06:39 AM
#9
Sleep mode
-
Feb 27th, 2004, 06:51 AM
#10
Thread Starter
Fanatic Member
Hi Pirate.
True, but what if you convert it to a bitmap? will it still stay aplhablended?
That is way I previously searched for, and found, some code to fix the alphablend.
But anyways, I'll implement your code into my app on my XP machine, and I will soon enough find out wether I need to fix them or not, and if so, if my fix will work.
It's strange that the fix works on icons extracted with SHGetFileInfo and not ExtractIconEx
Thank's again for all your help.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 07:05 AM
#11
Sleep mode
-
Feb 27th, 2004, 07:15 AM
#12
Thread Starter
Fanatic Member
Hi.
the fix is just some code some guy at PSC wrote. Basically he creates a new bitmap object based on the iconinfo, and uses bitmap data to transfer it to another new bitmap object with 32bpp format, which restores the alphablend.
I'll post the code for the fix when I have tested your code against it.
But I have no idea what went wrong anyways. I extracted an icon using SHGetFileInfo and passed it to my fix function and it worked perfectly.
Then I extracted another icon using ExtracIconEx and ran that through my fix function and it returned a blank bitmap.
My guess is that there is some difference in the iconinfo returned by those two API's (Perhaps ExtractIconEx hasn't been updated to support alphablends?)
The purpose of my app is to extracticons from any file and save them as bitmaps. And I don't want to save a bitmap with that ugly black edge.
So I'm really anxious to get home and test your code...
I'll post the result later.
Thank's
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 07:41 AM
#13
Sleep mode
Since you're entrapped in these APIs , do you know if there's a way to return number of icons inside a file . ??
-
Feb 27th, 2004, 08:40 AM
#14
Thread Starter
Fanatic Member
Hi Pirate.
Calling the ExtractIconEx with index -1 and no pointers will return the number of icons.
VB Code:
<DllImport("shell32.dll", EntryPoint:="ExtractIconEx", CharSet:=CharSet.Auto)> _
Private Shared Function ExtractIconEx(ByVal Filename As String, ByVal IconIndex As Integer, ByRef hLargeIcon As IntPtr, ByRef hSmallIcon As IntPtr, ByVal Count As Integer) As Integer
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim systempath As String = Environment.GetFolderPath(Environment.SpecialFolder.System)
Dim filename As String = IO.Path.Combine(systempath, "shell32.dll")
MessageBox.Show("Shell32.DLL contains " & ExtractIconEx(filename, -1, Nothing, Nothing, 1) & " icons")
End Sub
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 09:15 AM
#15
Thread Starter
Fanatic Member
Hi Pirate.
I have a question about the code you posted.
It seems to only return 32x32 icons. What if I want the 16x16 icon?
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 09:52 AM
#16
Sleep mode
Then simply , do this :
VB Code:
e.Graphics.DrawIcon(ico, New Rectangle(0, 0, 16, 16))
Or
use the ugly SHGetFileInfo method .
btw , thanks for index -1 hook up . It worked
-
Feb 27th, 2004, 11:04 AM
#17
Thread Starter
Fanatic Member
Hi Pirate.
I finally got some of it to work. I'm sorry to say that I didn't use your code.
It turns out that it had been working all the time, except on the icons I had tried. Now I coincidently choose another index and it worked. So it works on some icons and not on others.
Now, ain't that some weird S**t?
Now I don't know what to do with the other icons. Perhaps they don't have an alphachannel?
Here's my code. Maybe you can figure it out?
VB Code:
Imports System.Runtime.InteropServices
Imports System.Drawing.Imaging
Public Class IconExtraction
#Region "API"
<DllImport("shell32.dll", EntryPoint:="ExtractIconEx", CharSet:=CharSet.Auto)> _
Private Shared Function ExtractIconEx(ByVal Filename As String, ByVal IconIndex As Integer, ByRef hIconLarge As IntPtr, ByRef hIconSmall As IntPtr, ByVal IconCount As Integer) As IntPtr
End Function
<DllImport("shell32.dll", EntryPoint:="SHGetFileInfo", CharSet:=CharSet.Auto)> _
Private Shared Function SHGetFileInfo(ByVal FileName As String, ByVal FileAttributes As Integer, ByRef Buffer As SHFileInfo, ByVal FileInfo As Integer, ByVal Flags As Integer) As IntPtr
End Function
<DllImport("user32", EntryPoint:="GetIconInfo", CharSet:=CharSet.Auto)> _
Private Shared Function GetIconInfo(ByVal hIcon As IntPtr, ByRef piconinfo As ICONINFO) As IntPtr
End Function
<DllImport("Gdi32", EntryPoint:="CreateDC", CharSet:=CharSet.Auto)> _
Private Shared Function CreateDC(ByVal Driver As String, ByVal DeviceName As String, ByVal Output As String, ByVal Mode As IntPtr) As IntPtr
End Function
<DllImport("Gdi32", EntryPoint:="GetDeviceCaps", CharSet:=CharSet.Auto)> _
Private Shared Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal Index As Integer) As Integer
End Function
<DllImport("Gdi32", EntryPoint:="DeleteDC", CharSet:=CharSet.Auto)> _
Private Shared Function DeleteDC(ByVal hDC As IntPtr) As Boolean
End Function
<DllImport("user32", EntryPoint:="DestroyIcon", CharSet:=CharSet.Auto)> _
Private Shared Function DestroyIcon(ByVal hIcon As IntPtr) As IntPtr
End Function
#End Region
#Region "Structures"
Private Structure SHFileInfo
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
Public szDisplayName As String
Public szTypeName As String
End Structure
Private Structure ICONINFO
Dim fIcon As Boolean
Dim xHotspot As Integer
Dim yHotspot As Integer
Dim hbmMask As IntPtr
Dim hbmColor As IntPtr
End Structure
#End Region
#Region "Constants"
Private Const SHGFI_ICON = &H100
Private Const SHGFI_SMALLICON = &H1 ' Small icon
Private Const SHGFI_LARGEICON = &H0 ' Large icon
Private Const SHGFI_USEFILEATTRIBUTES = &H10
Private Const BITSPIXEL As Integer = 12
Private Const PLANES As Integer = 14
#End Region
#Region "Private Functions"
'Used by the alphafix
Private Shared Function GetColorDepth() As Integer
Dim screenDC As IntPtr = CreateDC("DISPLAY", Nothing, Nothing, IntPtr.Zero)
Dim bitDepth As Integer = GetDeviceCaps(screenDC, BITSPIXEL)
bitDepth *= GetDeviceCaps(screenDC, PLANES)
DeleteDC(screenDC)
Return bitDepth
End Function
Private Shared Function FixAlphaBitmap(ByVal bmSource As Bitmap) As Bitmap
'WARNING! This function will fail if the passed bitmap is not of
'the correct Pixelformat.
Dim bmData As Imaging.BitmapData
Dim bmBounds As New Rectangle(0, 0, bmSource.Width, bmSource.Height)
'create a new bitmap with an ARGB format and point it to the same memory
'location as the original bitmap.
bmData = bmSource.LockBits(bmBounds, ImageLockMode.ReadOnly, bmSource.PixelFormat)
Dim dstBitmap As New Bitmap(bmData.Width, bmData.Height, bmData.Stride, PixelFormat.Format32bppArgb, bmData.Scan0)
bmSource.UnlockBits(bmData)
bmData = Nothing
Return dstBitmap
End Function
#End Region
Public Shared Function GetIconCount(ByVal FileName As String) As Integer
Dim hCount As IntPtr
hCount = ExtractIconEx(FileName, -1, Nothing, Nothing, 1)
Return hCount.ToInt32
End Function
Public Shared Function ExtractLargeIcon(ByVal FileName As String, ByVal Index As Integer) As Icon
Dim hIcon As IntPtr
ExtractIconEx(FileName, Index, hIcon, Nothing, 1)
Return Icon.FromHandle(hIcon)
End Function
Public Shared Function ExtractSmallIcon(ByVal FileName As String, ByVal Index As Integer) As Icon
Dim hIcon As IntPtr
ExtractIconEx(FileName, Index, Nothing, hIcon, 1)
Return Icon.FromHandle(hIcon)
End Function
Public Shared Function ExtractLargeAssociatedIcon(ByVal FileName As String) As Icon
Dim sh As New SHFileInfo()
SHGetFileInfo(FileName, 0, sh, Marshal.SizeOf(sh), SHGFI_ICON Or SHGFI_LARGEICON Or SHGFI_USEFILEATTRIBUTES)
GC.Collect()
Return Icon.FromHandle(sh.hIcon)
End Function
Public Shared Function ExtractSmallAssociatedIcon(ByVal FileName As String) As Icon
Dim sh As New SHFileInfo()
SHGetFileInfo(FileName, 0, sh, Marshal.SizeOf(sh), SHGFI_ICON Or SHGFI_SMALLICON Or SHGFI_USEFILEATTRIBUTES)
GC.Collect()
Return Icon.FromHandle(sh.hIcon)
End Function
Public Shared Function ConvertToBitmap(ByVal hIcon As IntPtr) As Bitmap
Dim B As Bitmap
Dim hBitmap As IntPtr
Dim bmp As Bitmap
Dim ii As New ICONINFO()
GetIconInfo(hIcon, ii)
hBitmap = ii.hbmColor
bmp = Bitmap.FromHbitmap(hBitmap)
If Environment.OSVersion.Version.Major >= 5 AndAlso _
Environment.OSVersion.Version.Minor >= 1 AndAlso _
GetColorDepth() = 32 Then
B = FixAlphaBitmap(bmp).Clone
Else
B = Bitmap.FromHicon(hIcon)
End If
DestroyIcon(hBitmap)
DestroyIcon(hIcon)
GC.Collect()
hBitmap = Nothing
bmp = Nothing
ii = Nothing
Return B
End Function
End Class
Last edited by pax; Feb 27th, 2004 at 11:20 AM.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 11:16 AM
#18
-
Feb 27th, 2004, 11:21 AM
#19
Thread Starter
Fanatic Member
Hi Pirate.
It turns out it was wrong what I just posted, so while you were posting I was editing
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 12:31 PM
#20
Thread Starter
Fanatic Member
Finally...
It was because they had no alphachannel, so all ARGB values of the returned bitmap had an alphavalue of 0.
So I solved it by lopping through all pixels in the fixed bitmap and if I found and alphachannel <> 0 then I knew the bitmap was ok.
If I didn't find any I knew the bitmap was blank, returned nothing causing an exception in the calling procedure, which I could catch, so I could return the a bitmap converted using icon.fromhandle.
Phew, that was hard to describe I hope it made sence.
Here's the new code:
VB Code:
Imports System.Runtime.InteropServices
Imports System.Drawing.Imaging
Public Class IconExtraction
#Region "API"
<DllImport("shell32.dll", EntryPoint:="ExtractIconEx", CharSet:=CharSet.Auto)> _
Private Shared Function ExtractIconEx(ByVal Filename As String, ByVal IconIndex As Integer, ByRef hIconLarge As IntPtr, ByRef hIconSmall As IntPtr, ByVal IconCount As Integer) As IntPtr
End Function
<DllImport("shell32.dll", EntryPoint:="SHGetFileInfo", CharSet:=CharSet.Auto)> _
Private Shared Function SHGetFileInfo(ByVal FileName As String, ByVal FileAttributes As Integer, ByRef Buffer As SHFileInfo, ByVal FileInfo As Integer, ByVal Flags As Integer) As IntPtr
End Function
<DllImport("user32", EntryPoint:="GetIconInfo", CharSet:=CharSet.Auto)> _
Private Shared Function GetIconInfo(ByVal hIcon As IntPtr, ByRef piconinfo As ICONINFO) As IntPtr
End Function
<DllImport("Gdi32", EntryPoint:="CreateDC", CharSet:=CharSet.Auto)> _
Private Shared Function CreateDC(ByVal Driver As String, ByVal DeviceName As String, ByVal Output As String, ByVal Mode As IntPtr) As IntPtr
End Function
<DllImport("Gdi32", EntryPoint:="GetDeviceCaps", CharSet:=CharSet.Auto)> _
Private Shared Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal Index As Integer) As Integer
End Function
<DllImport("Gdi32", EntryPoint:="DeleteDC", CharSet:=CharSet.Auto)> _
Private Shared Function DeleteDC(ByVal hDC As IntPtr) As Boolean
End Function
<DllImport("user32", EntryPoint:="DestroyIcon", CharSet:=CharSet.Auto)> _
Private Shared Function DestroyIcon(ByVal hIcon As IntPtr) As IntPtr
End Function
#End Region
#Region "Structures"
Private Structure SHFileInfo
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
Public szDisplayName As String
Public szTypeName As String
End Structure
Private Structure ICONINFO
Dim fIcon As Boolean
Dim xHotspot As Integer
Dim yHotspot As Integer
Dim hbmMask As IntPtr
Dim hbmColor As IntPtr
End Structure
#End Region
#Region "Constants"
Private Const SHGFI_ICON = &H100
Private Const SHGFI_SMALLICON = &H1 ' Small icon
Private Const SHGFI_LARGEICON = &H0 ' Large icon
Private Const SHGFI_USEFILEATTRIBUTES = &H10
Private Const BITSPIXEL As Integer = 12
Private Const PLANES As Integer = 14
#End Region
#Region "Private Functions"
'Used by the alphafix
Private Shared Function GetColorDepth() As Integer
Dim screenDC As IntPtr = CreateDC("DISPLAY", Nothing, Nothing, IntPtr.Zero)
Dim bitDepth As Integer = GetDeviceCaps(screenDC, BITSPIXEL)
bitDepth *= GetDeviceCaps(screenDC, PLANES)
DeleteDC(screenDC)
Return bitDepth
End Function
Private Shared Function FixAlphaBitmap(ByVal bmSource As Bitmap) As Bitmap
Dim X, Y As Integer
Dim C As Color
Dim bAlphaFound As Boolean
'WARNING! This function will fail if the passed bitmap is not of
'the correct Pixelformat.
Dim bmData As Imaging.BitmapData
Dim bmBounds As New Rectangle(0, 0, bmSource.Width, bmSource.Height)
'create a new bitmap with an ARGB format and point it to the same memory
'location as the original bitmap.
bmData = bmSource.LockBits(bmBounds, ImageLockMode.ReadOnly, bmSource.PixelFormat)
Dim dstBitmap As New Bitmap(bmData.Width, bmData.Height, bmData.Stride, PixelFormat.Format32bppArgb, bmData.Scan0)
bmSource.UnlockBits(bmData)
bmData = Nothing
For Y = 0 To dstBitmap.Height - 1
For X = 0 To dstBitmap.Width - 1
C = dstBitmap.GetPixel(X, Y)
If C.A <> 0 Then
bAlphaFound = True
Exit For
End If
Next
If bAlphaFound = True Then Exit For
Next
If Not bAlphaFound Then dstBitmap = Nothing
Return dstBitmap
End Function
#End Region
Public Shared Function GetIconCount(ByVal FileName As String) As Integer
Dim hCount As IntPtr
hCount = ExtractIconEx(FileName, -1, Nothing, Nothing, 1)
Return hCount.ToInt32
End Function
Public Shared Function ExtractLargeIcon(ByVal FileName As String, ByVal Index As Integer) As Icon
Dim hIcon As IntPtr
ExtractIconEx(FileName, Index, hIcon, Nothing, 1)
Return Icon.FromHandle(hIcon)
End Function
Public Shared Function ExtractSmallIcon(ByVal FileName As String, ByVal Index As Integer) As Icon
Dim hIcon As IntPtr
ExtractIconEx(FileName, Index, Nothing, hIcon, 1)
Return Icon.FromHandle(hIcon)
End Function
Public Shared Function ExtractLargeAssociatedIcon(ByVal FileName As String) As Icon
Dim sh As New SHFileInfo()
SHGetFileInfo(FileName, 0, sh, Marshal.SizeOf(sh), SHGFI_ICON Or SHGFI_LARGEICON Or SHGFI_USEFILEATTRIBUTES)
GC.Collect()
Return Icon.FromHandle(sh.hIcon)
End Function
Public Shared Function ExtractSmallAssociatedIcon(ByVal FileName As String) As Icon
Dim sh As New SHFileInfo()
SHGetFileInfo(FileName, 0, sh, Marshal.SizeOf(sh), SHGFI_ICON Or SHGFI_SMALLICON Or SHGFI_USEFILEATTRIBUTES)
GC.Collect()
Return Icon.FromHandle(sh.hIcon)
End Function
Public Shared Function ConvertToBitmap(ByVal hIcon As IntPtr) As Bitmap
Dim B As Bitmap
Dim hBitmap As IntPtr
Dim bmp As Bitmap
Dim ii As New ICONINFO()
GetIconInfo(hIcon, ii)
hBitmap = ii.hbmColor
bmp = Bitmap.FromHbitmap(hBitmap)
If Environment.OSVersion.Version.Major >= 5 AndAlso _
Environment.OSVersion.Version.Minor >= 1 AndAlso _
GetColorDepth() = 32 Then
Try
B = FixAlphaBitmap(bmp).Clone
Catch
If B Is Nothing Then B = Bitmap.FromHicon(hIcon)
End Try
Else
B = Bitmap.FromHicon(hIcon)
End If
DestroyIcon(hBitmap)
DestroyIcon(hIcon)
GC.Collect()
hBitmap = Nothing
bmp = Nothing
ii = Nothing
Return B
End Function
End Class
So it seems I've been going about this all wrong from the get go.
But all's well that ends well.
Thank's again Pirate, and sorry if I wasted your time.
At least, I hope you can use this in the future.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 27th, 2004, 12:53 PM
#21
-
Jul 12th, 2005, 05:06 PM
#22
Addicted Member
Re: Ugly icons...[RESOLVED]
 Originally Posted by Pirate
Umm , I'm not sure but let's be optimistic and say it stay alphablended .
What fix is that you're talking about  ? Don't mess much with those API again  . 
bitmaps CANT be alpha-blended... the operating system uses magic pink to use transparency with bitmaps though...
you guys need to use png...
-
Jul 12th, 2005, 06:03 PM
#23
Member
Re: Ugly icons...[RESOLVED]
I am looking for this code too, but the error says:
Assembly is not declared.
Do I need to import something?
VB.NET 2003 Professional Edition
VB
C#
C++
J#
-
Jul 12th, 2005, 06:16 PM
#24
Sleep mode
Where does it say this error ? can you show some code ?
Yes , you should import System.Runtime.Interoper.. namespace .
 Originally Posted by tmasboa
I am looking for this code too, but the error says:
Assembly is not declared.
Do I need to import something?
-
Jul 12th, 2005, 06:20 PM
#25
Member
Re: Ugly icons...[RESOLVED]
Here's my code:
VB Code:
Imports System.runtime.InteropServices
Imports System.Drawing
Public Class Form1
Inherits System.Windows.Forms.Form
<DllImport("shell32.dll", EntryPoint:="ExtractAssociatedIcon")> _
Private Shared Function ExtractAssociatedIcon(ByVal hInst As System.IntPtr, <MarshalAs(UnmanagedType.LPStr)> ByVal lpIconPath As String, ByRef lpiIcon As Integer) As System.IntPtr
End Function
Dim ico As Icon
Private Sub GetIconInfo()
Dim iconPath As String = "C:\windows\system32\shell32.dll"
Dim hInst As IntPtr = Marshal.GetHINSTANCE([Assembly].GetExecutingAssembly().GetModules()(0))
Dim iIcon As Int32
Dim hIcon As IntPtr
'6 is the index you need to change only .
hIcon = ExtractAssociatedIcon(hInst, iconPath, 6)
ico = Icon.FromHandle(hIcon)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetIconInfo()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.DrawIcon(ico, 0, 0)
End Sub
End Class
I took out the Windows form designer... region because it seemed to be irrelevent
edit: It gives me error before I run it:
Name 'Assembly' is not declared.
Thanks
VB.NET 2003 Professional Edition
VB
C#
C++
J#
-
Jul 12th, 2005, 06:31 PM
#26
Sleep mode
Re: Ugly icons...[RESOLVED]
oh ok , it might be the assembly namesapce not imported . try this
Imports System.Reflection.Assembly (at the very top of your class declaration)
-
Jul 12th, 2005, 06:41 PM
#27
Sleep mode
i don't think that will fix it , it's complaining about this assembly var , try this :
Dim hInst As IntPtr = Marshal.GetHINSTANCE(Me.GetType.Assembly.GetExecutingAssembly().GetModules()(0))
-
Jul 12th, 2005, 06:42 PM
#28
Member
Re: Ugly icons...[RESOLVED]
hmm... still doesn't work
But i tried:
Imports System.Reflection
and it worked!
thanks
VB.NET 2003 Professional Edition
VB
C#
C++
J#
-
Jul 12th, 2005, 06:46 PM
#29
Sleep mode
Re: Ugly icons...[RESOLVED]
i hope pax doesn't get mad about hijacking his thread like that
-
Jul 12th, 2005, 07:08 PM
#30
Member
Re: Ugly icons...[RESOLVED]
VB.NET 2003 Professional Edition
VB
C#
C++
J#
-
Dec 14th, 2007, 09:01 AM
#31
New Member
Re: Ugly icons...[RESOLVED]
Hello Pax
I've found two minor bugs in your code.
Lines 160/161:
Old:
vb Code:
If Environment.OSVersion.Version.Major >= 5 AndAlso _
Environment.OSVersion.Version.Minor >= 1 AndAlso _
GetColorDepth() = 32 Then
'do something
End If
New:
vb Code:
Static myVersionBreak As New Version(5, 1, 0, 0)
If (Environment.OSVersion.Version >= myVersionBreak) AndAlso _
(GetColorDepth() = 32) Then
'do something
End If
Reason:
If there comes an OS Version 6.0, 7.0, 8.0 etc. your code is gonna fail as the minor version is not greater than 1. Remark: Luckily the version object overrides the compare operators what allows us to compare two version objects directly.
Lines 44.5 and 36.5:
The following line is missing:
vb Code:
<StructLayout(LayoutKind.Sequential)> _
Reason:
Interopability structures should be labeled with this attribute to prevent the compiler from rearranging the field order for memory optimization reasons.
Thank you for the code and bye
Chris
-
Dec 14th, 2007, 09:07 AM
#32
New Member
Re: Ugly icons...[RESOLVED]
(Sorry, posted it twice accidentally. Please delete this one...)
Last edited by CHHA; Dec 14th, 2007 at 09:10 AM.
Reason: Duplicate
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|