MyException - 我的异常网
当前位置:我的异常网» VB » vb如何得到程序文件图标

vb如何得到程序文件图标

www.MyException.Cn,网友分享于:2013-01-01   浏览:13次
vb怎么得到程序文件图标
如题。
跟任务管理器中的列表一样,在每个程序名称前面都显示相应程序文件的图标,这个是怎么做的,也就是怎么获得那些程序的图标?

请各位高手指教。最好能有具体的源代码。谢了

------解决方案--------------------
Public Declare Function ExtractIcon Lib "shell32.dll " Alias "ExtractIconA " (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Public Declare Function ExtractIconEx Lib "shell32.dll " Alias "ExtractIconExA " (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long

------解决方案--------------------
窗体的有个属性icon,点击后面的...选择自己做好的图标就可以了.这个就是任务管理器前面的那个图表..
------解决方案--------------------
Private Declare Function ExtractIcon Lib "shell32.dll " Alias "ExtractIconA "
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As
Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll "
(lpPictDesc As PICTDESC, riid As Any, ByVal fPictureOwnsHandle As Long,
IPic As IPicture) As Long

Private Type PICTDESC
Size As Long
Type As Long
hBmpOrIcon As Long
hPal As Long
End Type

' 取得EXE文件图标
' 参数:EXE文件完整路径名
Public Function GetAppIco(ByVal PathName As String) As StdPicture

Dim lRet As Long
Dim aGuid(0 To 3) As Long
Dim oNewPic As IPicture
Dim lpPictDesc As PICTDESC

lRet = FileLen(PathName) ' 文件是否存在?
lRet = ExtractIcon(App.hInstance, PathName, 0)

If lRet Then

lpPictDesc.Size = Len(lpPictDesc)
lpPictDesc.Type = vbPicTypeIcon
lpPictDesc.hBmpOrIcon = lRet

aGuid(0) = &H7BF80980
aGuid(1) = &H101ABF32
aGuid(2) = &HAA00BB8B
aGuid(3) = &HAB0C3000

' 将图标转换成 Picture 对象
OleCreatePictureIndirect lpPictDesc, aGuid(0), True, oNewPic

Set GetAppIco = oNewPic

End If

End Function

Private Sub Command1_Click()
Set Me.Icon = GetAppIco( "C:\WINDOWS\explorer.exe ")
End Sub
相关解决方案
  • 暂无相关解决方案
软件开发程序错误异常ExceptionCopyright © 2009-2014MyException 版权所有