Type Class_ImageList
Private : 
   m_hWndForm As HWnd '控件句柄
   m_IDC As Long     '控件IDC
   Declare Function GetFP() As FormControlsPro_TYPE ptr '返回控件保存数据的指针（一般是类自己用）
Public : 
   Declare Constructor
   Declare Destructor
   Declare Property hWndForm() As.hWnd         '返回/设置控件所在的窗口句柄，主要用于多开同一个窗口后，要使用控件前，必须先指定控件所在的窗口句柄，才能正常使用控件。
   Declare Property hWndForm(ByVal hWndParent As.hWnd) '获取控件所在的窗口句柄（父窗口）
   Declare Property IDC() As Long             '返回/设置控件IDC，控件标识符，1个窗口里每个控件IDC都是唯一的，包括控件数组。（不可随意修改，系统自动处理）
   Declare Property IDC(NewIDC As Long)
   Declare Property Tag() As CWSTR                       '存储程序所需的附加数据。
   Declare Property Tag(ByVal sText As CWSTR)
   Declare Sub SetSize(w As Long ,h As Long ) '设置图像尺寸（像素），将会销毁原图像列表，重新创建。
   Declare Function GetSizeW() As Long  '获取图像尺寸（像素）
   Declare Function GetSizeH() As Long  '获取图像尺寸（像素）
   Declare Function GethImageList() As hImageList '获取图像列表句柄，给TV LV 绑定用
   Declare Function Add(ResImg As String) As Long  '新增图像（需要资源名称），成功返回新图像的索引，否则返回-1。
   Declare Property BackColor() As Long           '返回/设置背景色：：特殊合成色，设置用：BGRA (r, g, b, a) ，获取用：GetCodeColorGDI 或 GetCodeColorGDIplue 转换
   Declare Property BackColor(nColor As Long)
   Declare Function Draw(DC AS HDC,i AS LONG,x AS LONG,y AS LONG) As Long  '在指定的设备上下文中绘制图像列表项。成功返回非零值，否则返回零。
   Declare Function GetIcon(i AS LONG) As HICON  '从图像列表中的图像创建一个图标。成功返回图像列表的句柄，否则返回NULL。调用应用程序有责任使用DestroyIcon函数销毁从此函数返回的图标。

End Type

'----------------------------------------------------------------------------------------------------------------------------------------------------------------
Constructor Class_ImageList
   '注意：由于窗口类是永久的，全局变量，因此这里从开软件到关软件只执行1次。
End Constructor

Destructor Class_ImageList
   '注意：由于窗口类是永久的，全局变量，因此为了可以完成特殊功能，Destructor 会重复执行
   '1，每次窗口销毁  就执行1次 Destructor  ，多次显示和关窗口就重复操作
   '2，退出软件  执行1次 Destructor
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < 16 Then Return 
      Dim zz As HIMAGELIST Ptr = Cast(Any Ptr,StrPtr(fp->nData))
      ImageList_Destroy *zz
      fp->nData=""
   End If 
End Destructor
Function Class_ImageList.GetFP() As FormControlsPro_TYPE ptr '返回自己控件的指针
   Dim fp As FormControlsPro_TYPE ptr = GetPropW(m_hWndForm, "FCP_TYPE_PTR")
   While fp
      if fp->IDC = m_IDC Then Return fp      
      fp = fp->VrControls
   Wend

End Function
Property Class_ImageList.hWndForm() As .hWnd         '返回/设置控件所在的窗口句柄
      Return m_hWndForm
End Property
Property Class_ImageList.hWndForm(ByVal hWndParent As .hWnd)
   m_hWndForm = hWndParent
End Property
Property Class_ImageList.IDC() As Long     
   Return m_IDC
End Property
Property Class_ImageList.IDC(ByVal NewIDC As Long)
   m_IDC  =NewIDC
End Property
Sub Class_ImageList.SetSize(w As Long, h As Long) '设置图像尺寸（像素），将会销毁原图像列表，重新创建。
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < 16 Then fp->nData = String(16, 0)
      Dim dz As UInteger = Cast(UInteger, StrPtr(fp->nData))
      Dim zz As HIMAGELIST Ptr = Cast(Any Ptr, dz)
      if *zz Then ImageList_Destroy *zz
      if w = 0 Then w = 16
      if h = 0 Then h = 16
       *zz = ImageList_Create(w, h, ILC_COLOR32, 10, 10)
      dz += 8                     
      Dim wh As Long Ptr = Cast(Any Ptr, dz)
      wh[0] = w
      wh[1] = h
   End If
End Sub
Function Class_ImageList.GetSizeW() As Long  '获取图像尺寸（像素）
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < 16 Then fp->nData = String(16, 0)
      Dim dz As UInteger = Cast(UInteger, StrPtr(fp->nData))
      dz += 8
      Dim wh As Long Ptr = Cast(Any Ptr, dz)
      Return wh[0] 
   End If
End Function
Function Class_ImageList.GetSizeH() As Long  '获取图像尺寸（像素）
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < 16 Then fp->nData = String(16, 0)
      Dim dz As UInteger = Cast(UInteger, StrPtr(fp->nData))
      dz += 8
      Dim wh As Long Ptr = Cast(Any Ptr, dz)
      Return wh[1] 
   End If
End Function
Function Class_ImageList.GethImageList() As hImageList '获取图像列表句柄，给TV LV 绑定用
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < 16 Then fp->nData = String(16, 0)
      Dim dz As UInteger = Cast(UInteger, StrPtr(fp->nData))
      Dim zz As HIMAGELIST Ptr = Cast(Any Ptr, dz)
      Function =*zz 
   End If
End Function
Function Class_ImageList.Add(ResImg As String) As Long  '新增图像（需要资源名称），成功返回新图像的索引，否则返回-1。
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   Dim r As Long = -1
   if fp then
      if Len(fp->nData) < 16 Then fp->nData = String(16, 0)
      Dim dz As UInteger = Cast(UInteger, StrPtr(fp->nData))
      Dim zz As HIMAGELIST Ptr = Cast(Any Ptr, dz)
      Dim nIcon As HICON
      if Left(ResImg, 7) = "RCDATA_" Then
         nIcon = AfxGdipIconFromRes(App.hInstance, ResImg)
      Elseif Left(ResImg, 7) = "BITMAP_" Then
         Dim nBmp As HBITMAP = LoadImageA(app.hInstance, ResImg, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR)
         Dim po As ICONINFO
         po.fIcon = TRUE
         po.hbmColor = nBmp
         po.hbmMask = nBmp
         nIcon = CreateIconIndirect(@po)
         DeleteObject nBmp
      Elseif Left(ResImg, 5) = "ICON_" Then
'         nIcon = LoadImageA(app.hInstance, ResImg, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR)  '从资源里加载图标
         nIcon = LoadIconA(App.hInstance, ResImg)
      End if
      r = ImageList_ReplaceIcon( *zz, -1, nIcon)
      DestroyIcon nIcon
   End If
   Function = r
End Function
Property Class_ImageList.BackColor() As Long                  '返回/设置背景色： RGB 颜色值(用 BGR(r, g, b) 获取)
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      Return fp->BackColor
   end if
End Property
Property Class_ImageList.BackColor(nColor As Long)
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      fp->BackColor = nColor
      if Len(fp->nData) < 16 Then Return 
      Dim dz As UInteger = Cast(UInteger, StrPtr(fp->nData))
      Dim zz As HIMAGELIST Ptr = Cast(Any Ptr, dz)
      ImageList_SetBkColor  *zz ,GetCodeColorGDI(nColor)
   End If
End Property
Function Class_ImageList.Draw(DC AS HDC, i AS LONG, x AS LONG, y AS LONG) As Long  '在指定的设备上下文中绘制图像列表项。成功返回非零值，否则返回零。
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < 16 Then fp->nData = String(16, 0)
      Dim dz As UInteger = Cast(UInteger, StrPtr(fp->nData))
      Dim zz As HIMAGELIST Ptr = Cast(Any Ptr, dz)
      Function = ImageList_Draw( *zz, i, DC, x, y, ILD_TRANSPARENT)
   End If
End Function
Function Class_ImageList.GetIcon(i AS LONG) As HICON 
   Dim fp As FormControlsPro_TYPE ptr = GetFP()
   if fp then
      if Len(fp->nData) < 16 Then fp->nData = String(16, 0)
      Dim dz As UInteger = Cast(UInteger, StrPtr(fp->nData))
      Dim zz As HIMAGELIST Ptr = Cast(Any Ptr, dz)
      Function = ImageList_GetIcon( *zz, i, ILD_TRANSPARENT)
   End If
End Function

