1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| Option Explicit On
Imports System
Imports System.Drawing
Imports Microsoft.VisualBasic
Imports Edanmo.ShellExtensions
Imports NTFSStreams.NtfsStream
Imports FileZitorIC.c2i.IO.FileInfo
Imports System.Runtime.InteropServices
Namespace FileZitorIC
< _
ExtensionFileTypes(".customExtension"), _
ComClass(IconHandlingClass.ClassId, IconHandlingClass.InterfaceId, IconHandlingClass.EventsId) _
> _
Public Class IconHandlingClass
Inherits Edanmo.ShellExtensions.IconHandlerBase
Private Declare Function SendNotifyMessage Lib "user32" Alias "SendNotifyMessageA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const HWND_BROADCAST = &HFFFF
Private Const WM_SETTINGCHANGE = &H1A
Private Declare Ansi Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoW" ( _
ByVal pszPath As String, _
ByVal dwFileAttributes As Integer, _
ByRef psfi As c2i.IO.FileInfo.SHFILEINFO, _
ByVal cbFileInfo As Integer, _
ByVal uFlags As Integer) As Integer
Public Const ClassId As String = "771B82BB-5A8C-43f0-B3E0-E3D25A1F7F95"
Public Const InterfaceId As String = "F856C01B-36DE-4b7b-8EF4-2AE03CB90548"
Public Const EventsId As String = "1C500ECD-EAC3-4ddd-9F34-AEC22AEF1AE9"
Public Overrides Sub OnExtractIcon(ByVal Filename As String, ByVal IconIndex As Integer, ByRef LargeIcon As IntPtr, ByRef SmallIcon As IntPtr, ByVal LargeSize As Integer, ByVal SmallSize As Integer)
Dim currentFileInfo As New System.IO.FileInfo(Me.Filename)
Dim image As Image
Dim Large, Small As Bitmap
On Error Resume Next
If (readStreamData(Me.Filename, "IconHandler", 2) IsNot Nothing) Then
image = readStreamData(Me.Filename, "IconHandler", 2) ' Image Contenu dans la stream
' Create a large and small thumbnail
Small = DirectCast(image.GetThumbnailImage(SmallSize, SmallSize, Nothing, IntPtr.Zero), Bitmap)
Large = DirectCast(image.GetThumbnailImage(LargeSize, LargeSize, Nothing, IntPtr.Zero), Bitmap)
' Convert the thumbnails to icons
LargeIcon = Large.GetHicon()
SmallIcon = Small.GetHicon()
Small.Dispose()
Large.Dispose()
image.Dispose()
Else
Dim shfi As New SHFILEINFO
SHGetFileInfo(Me.Filename, FILE_ATTRIBUTE_NORMAL, shfi, Marshal.SizeOf(shfi), SHGFI_LARGEICON)
LargeIcon = shfi.hIcon
SHGetFileInfo(Me.Filename, FILE_ATTRIBUTE_NORMAL, shfi, Marshal.SizeOf(shfi), SHGFI_SMALLICON)
SmallIcon = shfi.hIcon
End If
End Sub
Public Overrides Function OnGetIconLocation(ByRef IconFile As String, ByRef IconIndex As Integer, ByVal Flags As Edanmo.ShellExtensions.IconHandlerFlags) As IconHandlerReturnFlags
Dim FileInfo As New System.IO.FileInfo(Me.Filename)
Dim getExt = FileInfo.Extension
If (readStreamData(Me.Filename, "IconHandler", 2) Is Nothing) Then
If (getExt = ".exe") Then
IconFile = Me.Filename
IconIndex = 1
Else
If (Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(getExt, True).GetValue("") IsNot Nothing) Then
If (Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(getExt, True).GetValue(""), True).OpenSubKey("DefaultIcon", True) IsNot Nothing) Then
If (Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(getExt, True).GetValue(""), True).OpenSubKey("DefaultIcon", True).GetValue("").ToString.Contains(",")) Then
IconFile = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(getExt, True).GetValue(""), True).OpenSubKey("DefaultIcon", True).GetValue("").ToString.Substring(0, Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(getExt, True).GetValue(""), True).OpenSubKey("DefaultIcon", True).GetValue("").ToString.LastIndexOf(","))
IconIndex = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(getExt, True).GetValue(""), True).OpenSubKey("DefaultIcon", True).GetValue("").ToString.Substring(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(getExt, True).GetValue(""), True).OpenSubKey("DefaultIcon", True).GetValue("").ToString.LastIndexOf("-") + 1)
MsgBox(IconFile)
Else
IconFile = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(getExt, True).GetValue(""), True).OpenSubKey("DefaultIcon", True).GetValue("")
IconIndex = IconIndex
MsgBox(IconFile)
End If
End If
Else
IconFile = IconFile
IconIndex = IconIndex
End If
End If
End If
Return IconHandlerReturnFlags.PerInstance Or IconHandlerReturnFlags.DontCache
End Function
End Class
End Namespace |
Partager