|
說明 這個程式是使用SHGetFileInfo() API 他的宣告如下 程式 '以下在Form ,一個CommonDialog1 一個Command button 2個PictureBox Dim hImgSmall As Long 'the handle to the system image list(Small Icon) Dim fName As String 'the file name to get icon from Dim fnFilter As String 'the file name filter Dim r As Long Dim hImgLarge As Long 'the handle to the system image list(Large Icon) Dim Info1 As String, Info2 As String 'get the file from the user fnFilter$ = "All Files (*.*)|*.*|" fnFilter = fnFilter & "Applications (*.exe)|*.exe|" fnFilter = fnFilter & "Windows Bitmap (*.bmp)|*.bmp|" fnFilter = fnFilter & "Icon Files (*.ico)|*.ico" CommonDialog1.CancelError = True CommonDialog1.Filter = fnFilter CommonDialog1.ShowOpen fName = CommonDialog1.filename 'get the system icon associated with that file hImgSmall& = SHGetFileInfo(fName$, 0, _ shinfo, Len(shinfo), _ BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON) hImgLarge& = SHGetFileInfo(fName$, 0&, _ shinfo, Len(shinfo), _ BASIC_SHGFI_FLAGS Or SHGFI_LARGEICON) 'fill in the labels with the image's file data Info1 = Left$(shinfo.szDisplayName, _ InStr(shinfo.szDisplayName, Chr$(0)) - 1) Info2 = Left$(shinfo.szTypeName, _ InStr(shinfo.szTypeName, Chr$(0)) - 1) Debug.Print Info1; Info2 Picture1.Picture = LoadPicture() Picture1.AutoRedraw = True Picture2.Picture = LoadPicture() Picture2.AutoRedraw = True 'draw the associated icons into the pictureboxes r = ImageList_Draw(hImgSmall&, shinfo.iIcon, Picture1.hDC, 0, 0, ILD_TRANSPARENT) r = ImageList_Draw(hImgLarge&, shinfo.iIcon, Picture2.hDC, 0, 0, ILD_TRANSPARENT) 'realize the images by assigning its 'image property (where the icon was drawn) 'to the actual picture property Set Picture1.Picture = Picture1.Image Set Picture2.Picture = Picture2.Image End Sub '以下在.Bas Option Explicit Public Const SHGFI_DISPLAYNAME = &H200 Public Const SHGFI_EXETYPE = &H2000 Public Const SHGFI_LARGEICON = &H0 Public Const SHGFI_SHELLICONSIZE = &H4 Public Const SHGFI_SMALLICON = &H1 Public Const SHGFI_SYSICONINDEX = &H4000 Public Const SHGFI_TYPENAME = &H400 Public Const BASIC_SHGFI_FLAGS = SHGFI_TYPENAME _ Or SHGFI_SHELLICONSIZE Or SHGFI_SYSICONINDEX _ Or SHGFI_DISPLAYNAME Or SHGFI_EXETYPE Public Const MAX_PATH = 260 Public Const ILD_TRANSPARENT = &H1 Public Type SHFILEINFO hIcon As Long iIcon As Long dwAttributes As Long szDisplayName As String * MAX_PATH szTypeName As String * 80 End Type Public Declare Function SHGetFileInfo Lib _ "shell32.dll" Alias "SHGetFileInfoA" _ (ByVal pszPath As String, _ ByVal dwFileAttributes As Long, _ psfi As SHFILEINFO, _ ByVal cbSizeFileInfo As Long, _ ByVal uFlags As Long) As Long Public Declare Function ImageList_Draw Lib "comctl32.dll" _ (ByVal himl As Long, ByVal i As Long, _ ByVal hDCDest As Long, ByVal x As Long, _ ByVal y As Long, ByVal flags As Long) As Long Public shinfo As SHFILEINFO 相關資訊 文件出處 VB NET |
|
|
如果對本站有任何建議,歡迎來信給Honey,我們會盡快給您答覆 |