环境:XP sp2 ,vb6 (未打sp6补丁)
测试:
新建一个工程,在窗体上加一个ImageList控件(预先为控件加入几个图标),然后在窗体上加一个按钮,添加如下代码:
Private Declare Function ImageList_GetImageCount Lib "comctl32" ( _
ByVal himl As Long) As Long
Private Sub Command1_Click()
dim j as long
j = ImageList_GetImageCount( ImageList1.HIMAGELIST)
debug.print j
End Sub
不管ImageList1里有几个图标,发现ImageList_GetImageCount的返回值总为0
解决办法:
ImageList的ImageCount的值存放在.HIMAGELIST偏移4字节处,用copymemory取出即可:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Command1_Click()
Dim j As Long
CopyMemory i, ByVal Me.ImageList1.HIMAGELIST + 4, 4
Debug.Print j
End Sub