Delclaring a static array for use with CImage List!
-
:confused:I have a tree control class. I also have an image list that I want to associate with my tree. Why can't I declare a static array and initialize it with the id's of icons, in the resource file, in my tree control class?? :mad: I've included "resource.h" so I should know what the IDI's are...
class RCanalTree : public CTreeCtrl { // Construction public: RCanalTree(CCanalManager *pCanalManager=NULL); // Attributes public: const CCanalManager* GetCanalManagerPointer() { return m_pCanalManager; } bool SetCanalManagerPointer(CCanalManager *pCanalManager); // Operations public: static int m_icons[]={ IDI_ICON_SYSTEM, IDI_ICON_CANAL, IDI_ICON_SITE, IDI_ICON_WELL, IDI_ICON_TURNOUT, IDI_ICON_PUMP, 0 // NULL place holder used to terminate the array. }; virtual void Populate(); int DeleteChildren(HTREEITEM hParent); HTREEITEM GetDepthNextItem(HTREEITEM hItem); HTREEITEM FindItem(const char *name, int dwData); HTREEITEM InsertChildItem(const char *name, int dImage, HTREEITEM hParent, DWORD data, int iCheck=-1, bool bCondition=true); // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(RCanalTree) //}}AFX_VIRTUAL // Implementation public: bool InitializeImageList(); int GetImageIndexFor(int idOfIcon); bool DeleteChildItem(HTREEITEM hParent, const char* name, DWORD data); virtual void UpdateImages(); virtual EnumForOnCheck OnCheck(HTREEITEM hItem, bool bNowChecked); int GetIconIndex(int idOfIcon); virtual ~RCanalTree(); // Generated message map functions protected: bool IsScheduleLocked(); CCanalManager* m_pCanalManager; CImageList *pImageList; //{{AFX_MSG(RCanalTree) afx_msg void OnLButtonDown(UINT nFlags, CPoint point); //}}AFX_MSG DECLARE_MESSAGE_MAP() };
baaaah! -
:confused:I have a tree control class. I also have an image list that I want to associate with my tree. Why can't I declare a static array and initialize it with the id's of icons, in the resource file, in my tree control class?? :mad: I've included "resource.h" so I should know what the IDI's are...
class RCanalTree : public CTreeCtrl { // Construction public: RCanalTree(CCanalManager *pCanalManager=NULL); // Attributes public: const CCanalManager* GetCanalManagerPointer() { return m_pCanalManager; } bool SetCanalManagerPointer(CCanalManager *pCanalManager); // Operations public: static int m_icons[]={ IDI_ICON_SYSTEM, IDI_ICON_CANAL, IDI_ICON_SITE, IDI_ICON_WELL, IDI_ICON_TURNOUT, IDI_ICON_PUMP, 0 // NULL place holder used to terminate the array. }; virtual void Populate(); int DeleteChildren(HTREEITEM hParent); HTREEITEM GetDepthNextItem(HTREEITEM hItem); HTREEITEM FindItem(const char *name, int dwData); HTREEITEM InsertChildItem(const char *name, int dImage, HTREEITEM hParent, DWORD data, int iCheck=-1, bool bCondition=true); // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(RCanalTree) //}}AFX_VIRTUAL // Implementation public: bool InitializeImageList(); int GetImageIndexFor(int idOfIcon); bool DeleteChildItem(HTREEITEM hParent, const char* name, DWORD data); virtual void UpdateImages(); virtual EnumForOnCheck OnCheck(HTREEITEM hItem, bool bNowChecked); int GetIconIndex(int idOfIcon); virtual ~RCanalTree(); // Generated message map functions protected: bool IsScheduleLocked(); CCanalManager* m_pCanalManager; CImageList *pImageList; //{{AFX_MSG(RCanalTree) afx_msg void OnLButtonDown(UINT nFlags, CPoint point); //}}AFX_MSG DECLARE_MESSAGE_MAP() };
baaaah!Read up on how to use static member variables. Initialize it outside of the declaration like this:
class RCanalTree : public CTreeCtrl
{
...
static int m_icons[];
...
};...
int RCanalTree::m_icons[]={
IDI_ICON_SYSTEM,
IDI_ICON_CANAL,
IDI_ICON_SITE,
IDI_ICON_WELL,
IDI_ICON_TURNOUT,
IDI_ICON_PUMP,
0 // NULL place holder used to terminate the array.
};