• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Windows/Control/ImageList.h
2 
3 #ifndef __WINDOWS_CONTROL_IMAGE_LIST_H
4 #define __WINDOWS_CONTROL_IMAGE_LIST_H
5 
6 #include <commctrl.h>
7 
8 #include "../Defs.h"
9 
10 namespace NWindows {
11 namespace NControl {
12 
13 class CImageList
14 {
15   HIMAGELIST m_Object;
16 public:
HIMAGELIST()17   operator HIMAGELIST() const {return m_Object; }
CImageList()18   CImageList(): m_Object(NULL) {}
Attach(HIMAGELIST imageList)19   bool Attach(HIMAGELIST imageList)
20   {
21     if (imageList == NULL)
22       return false;
23     m_Object = imageList;
24     return true;
25   }
26 
Detach()27   HIMAGELIST Detach()
28   {
29     HIMAGELIST imageList = m_Object;
30     m_Object = NULL;
31     return imageList;
32   }
33 
Create(int width,int height,UINT flags,int initialNumber,int grow)34   bool Create(int width, int height, UINT flags, int initialNumber, int grow)
35   {
36     HIMAGELIST a = ImageList_Create(width, height, flags,
37       initialNumber, grow);
38     if (a == NULL)
39       return false;
40     return Attach(a);
41   }
42 
Destroy()43   bool Destroy() // DeleteImageList() in MFC
44   {
45     if (m_Object == NULL)
46       return false;
47     return BOOLToBool(ImageList_Destroy(Detach()));
48   }
49 
~CImageList()50   ~CImageList()
51     { Destroy(); }
52 
GetImageCount()53   int GetImageCount() const
54     { return ImageList_GetImageCount(m_Object); }
55 
GetImageInfo(int index,IMAGEINFO * imageInfo)56   bool GetImageInfo(int index, IMAGEINFO* imageInfo) const
57     { return BOOLToBool(ImageList_GetImageInfo(m_Object, index, imageInfo)); }
58 
59   int Add(HBITMAP hbmImage, HBITMAP hbmMask = 0)
60     { return ImageList_Add(m_Object, hbmImage, hbmMask); }
AddMasked(HBITMAP hbmImage,COLORREF mask)61   int AddMasked(HBITMAP hbmImage, COLORREF mask)
62     { return ImageList_AddMasked(m_Object, hbmImage, mask); }
AddIcon(HICON icon)63   int AddIcon(HICON icon)
64     { return ImageList_AddIcon(m_Object, icon); }
Replace(int index,HICON icon)65   int Replace(int index, HICON icon)
66     { return ImageList_ReplaceIcon(m_Object, index, icon); }
67 
68   // If index is -1, the function removes all images.
Remove(int index)69   bool Remove(int index)
70     { return BOOLToBool(ImageList_Remove(m_Object, index)); }
RemoveAll()71   bool RemoveAll()
72     { return BOOLToBool(ImageList_RemoveAll(m_Object)); }
73 
ExtractIcon(int index)74   HICON ExtractIcon(int index)
75     { return ImageList_ExtractIcon(NULL, m_Object, index); }
GetIcon(int index,UINT flags)76   HICON GetIcon(int index, UINT flags)
77     { return ImageList_GetIcon(m_Object, index, flags); }
78 
GetIconSize(int & width,int & height)79   bool GetIconSize(int &width, int &height) const
80     { return BOOLToBool(ImageList_GetIconSize(m_Object, &width, &height)); }
SetIconSize(int width,int height)81   bool SetIconSize(int width, int height)
82     { return BOOLToBool(ImageList_SetIconSize(m_Object, width, height)); }
83 };
84 
85 }}
86 
87 #endif
88