可以从\windows\explorer.exe中提取图标。使用以下的模块: Attribute VB_Name = "ExtractIcon" Option ExplicitPrivate Const MAX_PATH = 260 Private Const SHGFI_ICON = &H100 Private Const SHGFI_SYSICONINDEX = &H4000 ' get system icon index Private Const SHGFI_LARGEICON = &H0 ' get large icon Private Const SHGFI_SMALLICON = &H1 ' get small icon Private Const ILD_TRANSPARENT = &H1 ' 透明Private Type SHFILEINFO hIcon As Long ' out: icon iIcon As Long ' out: icon index dwAttributes As Long ' out: SFGAO_ flags szDisplayName As String * MAX_PATH ' out: display name (or path) szTypeName As String * 80 ' out: type name End Type Global lIcon& Global sSourcePgm$ Global sDestFile$Public Declare Function ExtractIconAPI Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long Public Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long Private Declare Function ImageList_Draw Lib "comctl32.dll" (ByVal himl&, ByVal i&, ByVal hDCDest&, ByVal x&, ByVal y&, ByVal flags&) As Long Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long' Public Function GetIcon(ByVal sPath$, oPictureBox As PictureBox) As Long Dim xPixels&, yPixels& xPixels = Screen.TwipsPerPixelX yPixels = Screen.TwipsPerPixelYDim himl&, rtn& Dim shinfo As SHFILEINFO Dim picLeft As Long Dim picTop As Long
himl = SHGetFileInfo(sPath, 0&, shinfo, Len(shinfo), SHGFI_SYSICONINDEX Or SHGFI_LARGEICON)
其实在上面那个模块中还可以使用API: Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long 那样会简单些!
不懂....能给个软件的名称吗?
Attribute VB_Name = "ExtractIcon"
Option ExplicitPrivate Const MAX_PATH = 260
Private Const SHGFI_ICON = &H100
Private Const SHGFI_SYSICONINDEX = &H4000 ' get system icon index
Private Const SHGFI_LARGEICON = &H0 ' get large icon
Private Const SHGFI_SMALLICON = &H1 ' get small icon
Private Const ILD_TRANSPARENT = &H1 ' 透明Private Type SHFILEINFO
hIcon As Long ' out: icon
iIcon As Long ' out: icon index
dwAttributes As Long ' out: SFGAO_ flags
szDisplayName As String * MAX_PATH ' out: display name (or path)
szTypeName As String * 80 ' out: type name
End Type
Global lIcon&
Global sSourcePgm$
Global sDestFile$Public Declare Function ExtractIconAPI Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Public Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Declare Function ImageList_Draw Lib "comctl32.dll" (ByVal himl&, ByVal i&, ByVal hDCDest&, ByVal x&, ByVal y&, ByVal flags&) As Long
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long'
Public Function GetIcon(ByVal sPath$, oPictureBox As PictureBox) As Long
Dim xPixels&, yPixels&
xPixels = Screen.TwipsPerPixelX
yPixels = Screen.TwipsPerPixelYDim himl&, rtn&
Dim shinfo As SHFILEINFO
Dim picLeft As Long
Dim picTop As Long
himl = SHGetFileInfo(sPath, 0&, shinfo, Len(shinfo), SHGFI_SYSICONINDEX Or SHGFI_LARGEICON)
If himl <= 0 Then GetIconNogray = -1: Exit Function '没有图标就返回-1
picLeft = (oPictureBox.ScaleWidth / xPixels) / 2 - 16
picTop = (oPictureBox.ScaleHeight / yPixels) / 2 - 16
oPictureBox.Picture = LoadPicture()
oPictureBox.AutoRedraw = True
rtn = ImageList_Draw(himl, shinfo.iIcon, oPictureBox.hdc, picLeft, picTop, ILD_TRANSPARENT)oPictureBox.RefreshGetIconNogray = himl '返回图标句柄End Function你只需要按以下方法调用就以实现:
dim hIcon as long'存放返回的图标句柄
hIcon=GetIcon("c:\windows\explorer.exe",aPictureBox)
'第一个参数与你系统位置有关;第二个参数用于显示图标;返回值是一个图标句柄,用于其它地方引用。
Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
那样会简单些!
.......好像不对,没那么复杂啊,我只是要几个系统提供的打印、文件、打开的那些图标啊
...........这不是找不到吗....