If you want to read only the file with the Count parameter, create your buttons, work with them, and then delete them all, and then CArray<CButton*> in my opinion. To make sure the buttons are removed, you can bind CArray to a helper, for example:
class CMyButtonArrayWrapper { public: CMyButtonArrayWrapper(); virtual ~CMyButtonArrayWrapper(); void ClearArray(); void Add(CButton* theButton); private: CArray<CButton*> m_Array; } CMyButtonArrayWrapper::CMyButtonArrayWrapper() { } CMyButtonArrayWrapper::~CMyButtonArrayWrapper() { ClearArray(); } void CMyButtonArrayWrapper::ClearArray() { for (int i=0; i<m_Array.GetSize(); i++) { CButton* aButton=m_Array.GetAt(i); if (aButton) delete aButton; } m_Array.RemoveAll(); } void CMyButtonArrayWrapper::Add(CButton* theButton) { m_Array.Add(theButton); }
Then add an object of this class as an element to your custom control ( m_MyButtonArrayWrapper ) and add your buttons with:
CButton* aButton=new CButton; aButton->Create( ... ); m_MyButtonArrayWrapper.Add(aButton);
If you need to add and remove buttons at random, CList may be better suited for performance reasons. (But you probably won't notice the performance difference with InsertAt / RemoveAt from CArray, except that your user interface has several thousand buttons. I think that would be more a cover than a user interface :))
source share