如何让VB6中的按钮控件的图标等于一个已经存在的应用程序的ICO图标?
如题!请懂的朋友尽量讲清楚一点,谢谢先!提取一个已经存在的应用程序的ICON图标指的是动态提取,也就是说这个按钮的图标是可以自定义的...
如题!
请懂的朋友尽量讲清楚一点,谢谢先!
提取一个已经存在的应用程序的ICON图标 指的是动态提取,也就是说这个按钮的图标是可以自定义的 展开
请懂的朋友尽量讲清楚一点,谢谢先!
提取一个已经存在的应用程序的ICON图标 指的是动态提取,也就是说这个按钮的图标是可以自定义的 展开
展开全部
将这些写在一个模块里:
Option Explicit
Public 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 Declare Function OleCreatePictureIndirect Lib "oleaut32.dll" (pDicDesc As TypeIcon, riid As CLSID, ByVal fown As Long, lpUnk As Object) As Long
Public Type TypeIcon
cbSize As Long
picType As PictureTypeConstants
hIcon As Long
End Type
Public 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
Public Const SHGFI_SMALLICON = &H1
Public Const SHGFI_LARGEICON = &H0
Public Const SHGFI_ICON = &H100
Public Type CLSID
id((123)) As Byte
End Type
Public Function GetFileIconS(ByVal sFileName As String) As StdPicture
Dim SHinfo As SHFILEINFO
Dim mTYPEICON As TypeIcon
Dim mCLSID As CLSID
Dim lFlag As Long
lFlag = SHGFI_SMALLICON
If Right(sFileName, 1) <> "\" Then sFileName = sFileName & "\"
Call SHGetFileInfo(sFileName, 0, SHinfo, Len(SHinfo), SHGFI_ICON + lFlag)
With mTYPEICON
.cbSize = Len(mTYPEICON)
.picType = vbPicTypeIcon
.hIcon = SHinfo.hIcon
End With
With mCLSID
.id(8) = &HC0
.id(15) = &H46
End With
Call OleCreatePictureIndirect(mTYPEICON, mCLSID, 1, GetFileIconS)
End Function
Public Function GetFileIconL(ByVal sFileName As String) As StdPicture
Dim SHinfo As SHFILEINFO
Dim mTYPEICON As TypeIcon
Dim mCLSID As CLSID
Dim lFlag As Long
lFlag = SHGFI_LARGEICON
If Right(sFileName, 1) <> "\" Then sFileName = sFileName & "\"
Call SHGetFileInfo(sFileName, 0, SHinfo, Len(SHinfo), SHGFI_ICON + lFlag)
With mTYPEICON
.cbSize = Len(mTYPEICON)
.picType = vbPicTypeIcon
.hIcon = SHinfo.hIcon
End With
With mCLSID
.id(8) = &HC0
.id(15) = &H46
End With
Call OleCreatePictureIndirect(mTYPEICON, mCLSID, 1, GetFileIconL)
End Function
然后就可以了。
其中 GetFileIconS 提取 16×16 的图标,GetFileIconL 提取 32×32 的图标。可以是任何存在的文件。
用法:
Private Sub Command2_Click()
Command1.Style = 1 'Graphic
Command1.Picture = GetFileIconS("C:\Windows\System32\cmd.exe")
End Sub
Private Sub Command3_Click()
Command1.Style = 1 'Graphic
Command1.Picture = GetFileIconL("C:\WIndows\System32\msvbvm60.dll")
End Sub
Option Explicit
Public 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 Declare Function OleCreatePictureIndirect Lib "oleaut32.dll" (pDicDesc As TypeIcon, riid As CLSID, ByVal fown As Long, lpUnk As Object) As Long
Public Type TypeIcon
cbSize As Long
picType As PictureTypeConstants
hIcon As Long
End Type
Public 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
Public Const SHGFI_SMALLICON = &H1
Public Const SHGFI_LARGEICON = &H0
Public Const SHGFI_ICON = &H100
Public Type CLSID
id((123)) As Byte
End Type
Public Function GetFileIconS(ByVal sFileName As String) As StdPicture
Dim SHinfo As SHFILEINFO
Dim mTYPEICON As TypeIcon
Dim mCLSID As CLSID
Dim lFlag As Long
lFlag = SHGFI_SMALLICON
If Right(sFileName, 1) <> "\" Then sFileName = sFileName & "\"
Call SHGetFileInfo(sFileName, 0, SHinfo, Len(SHinfo), SHGFI_ICON + lFlag)
With mTYPEICON
.cbSize = Len(mTYPEICON)
.picType = vbPicTypeIcon
.hIcon = SHinfo.hIcon
End With
With mCLSID
.id(8) = &HC0
.id(15) = &H46
End With
Call OleCreatePictureIndirect(mTYPEICON, mCLSID, 1, GetFileIconS)
End Function
Public Function GetFileIconL(ByVal sFileName As String) As StdPicture
Dim SHinfo As SHFILEINFO
Dim mTYPEICON As TypeIcon
Dim mCLSID As CLSID
Dim lFlag As Long
lFlag = SHGFI_LARGEICON
If Right(sFileName, 1) <> "\" Then sFileName = sFileName & "\"
Call SHGetFileInfo(sFileName, 0, SHinfo, Len(SHinfo), SHGFI_ICON + lFlag)
With mTYPEICON
.cbSize = Len(mTYPEICON)
.picType = vbPicTypeIcon
.hIcon = SHinfo.hIcon
End With
With mCLSID
.id(8) = &HC0
.id(15) = &H46
End With
Call OleCreatePictureIndirect(mTYPEICON, mCLSID, 1, GetFileIconL)
End Function
然后就可以了。
其中 GetFileIconS 提取 16×16 的图标,GetFileIconL 提取 32×32 的图标。可以是任何存在的文件。
用法:
Private Sub Command2_Click()
Command1.Style = 1 'Graphic
Command1.Picture = GetFileIconS("C:\Windows\System32\cmd.exe")
End Sub
Private Sub Command3_Click()
Command1.Style = 1 'Graphic
Command1.Picture = GetFileIconL("C:\WIndows\System32\msvbvm60.dll")
End Sub
展开全部
设计的时候 让 COMMAND。STYLE=1
然后再其PICTURE属性里设置图标
至于其他已有的程序的图标,可以用特殊的软件提取出来预先保存。
运行状态下,COMMAND的PICTURE属性也可以设置的
提取别的程序的图标的程序包括几个API函数,我忘了,继续BAIDU
然后再其PICTURE属性里设置图标
至于其他已有的程序的图标,可以用特殊的软件提取出来预先保存。
运行状态下,COMMAND的PICTURE属性也可以设置的
提取别的程序的图标的程序包括几个API函数,我忘了,继续BAIDU
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
将按钮的Style属性设为0-Standard
再将它的Picture属性设置成你要的图标。
再将它的Picture属性设置成你要的图标。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用提取程序icon的函数,提取后用代码放入imagelist控件,再通过command控件的图片索引属性动态加载图片上去
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
只需要在 command 的 PICTURE属性里设置图标,添加图标即可,添加图标时找到图标的保存位置就可以了!!!!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询