Imports System.Runtime.InteropServices

Public Class Form1

    Private Structure SHFileInfo
        Public hIcon As IntPtr
    End Structure

    Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" (ByVal pszPath As String, ByVal dwFileAttributes As Integer, ByRef psfi As SHFileInfo, ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As IntPtr
    Private Const SHGFI_ICON = &H100
    Private IcoFile As String = ""

    Private Sub DriveList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveList.SelectedIndexChanged
        DirList.Path = DriveList.Drive
    End Sub

    Private Sub DirList_Change(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DirList.Change
        FileList.Path = DirList.Path
    End Sub

    Private Sub PatternText_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PatternText.TextChanged
        FileList.Pattern = PatternText.Text
    End Sub

    Private Sub FileList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileList.Click
        IcoFile = FileList.Path & "\" & FileList.FileName
        Me.Text = "ShowIcons [" & IcoFile & "]"
        LargeIconPicture.Image = GetIcon(IcoFile)
    End Sub

    Private Function GetIcon(ByRef filename As String) As System.Drawing.Image
        Dim hImg As System.IntPtr
        Dim shinfo As New SHFileInfo
        hImg = SHGetFileInfo(filename, 0, shinfo, Marshal.SizeOf(shinfo), SHGFI_ICON)
        Dim icon As System.Drawing.Icon
        icon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
        Return icon.ToBitmap()
    End Function

End Class
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 浮雲 的頭像
    浮雲

    missice's Blog

    浮雲 發表在 痞客邦 留言(0) 人氣()