listview和imagelist的用法。非常着急。
用一下程序,取的输入法的ico图标,并把图标显示在listview中。给窗体上加载了一个imagelist和listview控件。结果是取某一个文件ico时能够正常显示,如果循环取第二个时,就提示imagelist被另一个控件绑定时不能修改的错误。请大家帮忙给看看,应该如何修改。
Option Explicit
Private Type PictDesc
cbSizeofStruct As Long
PicType As Long
hImage As Long
xExt As Long
yExt As Long
End Type
Private Type Guid
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
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 DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (lpPictDesc As PictDesc, riid As Guid, ByVal fPictureOwnsHandle As Long, ipic As IPicture) As Long
Private Function IconToPicture(ByVal hIcon As Long) As StdPicture
If hIcon = 0 Then Exit Function
Dim oNewPic As Picture
Dim tPicConv As PictDesc
Dim IGuid As Guid
With tPicConv
.cbSizeofStruct = Len(tPicConv)
.PicType = vbPicTypeIcon
.hImage = hIcon
End With
With IGuid
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With
OleCreatePictureIndirect tPicConv, IGuid, True, oNewPic
Set IconToPicture = oNewPic
End Function
Private Function BitmapToPicture(ByVal hBmp As Long) As StdPicture
Dim oNewPic As Picture, tPicConv As PictDesc, IGuid As Guid
With tPicConv
.cbSizeofStruct = Len(tPicConv)
.PicType = vbPicTypeBitmap
.hImage = hBmp
End With
With IGuid
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
OleCreatePictureIndirect tPicConv, IGuid, True, oNewPic
Set BitmapToPicture = oNewPic
End Function
Private Function getstrico(ImeNameStr As String)
Dim lIcon As Long, a As Long, sSourcePgm As String
Dim ret As Long
sSourcePgm = "c:\windows\system32\" & ImeNameStr '»»³ÌÄãµÄÎļþ·¾¶
Do
lIcon = ExtractIcon(App.hInstance, sSourcePgm, a)
If lIcon = 0 Then Exit Do
Call ImageList1.ListImages.Add(a + 1, , IconToPicture(lIcon))
a = a + 1
DestroyIcon lIcon
Loop
Set ListView1.Icons = ImageList1
If a = 0 Then
MsgBox "No Icons in this file!"
End If
Dim i As Long
For i = 0 To a - 1
ListView1.ListItems.Add Index:=i + 1, Text:="icon" + CStr(i + 1), Icon:=i + 1
Next
End Function
Private Sub Form_Load()
Dim i As Integer
Dim imename(11) As String
imename(0) = "gyhz.ime"
imename(1) = "sogoupy.ime"
imename(2) = "ALIPY0.5.1.30.IME"
imename(3) = "HWH_JX.IME"
For i = 0 To 3
getstrico (imename(i))
Next
End Sub
[解决办法]
没时间帮你调代码了。说下想法吧。
--------------------------------
取某一个文件ico时能够正常显示,如果循环取第二个时,就提示imagelist被另一个控件绑定时不能修改的错误。
-------------------------------
如错误提示所说,“imagelist被另一个控件绑定时不能修改”
而你下面的代码,
For i = 0 To 3getstrico (imename(i))Next