How to add Buttons dynamically
-
Hi, In my application, MDI, I have to read an output file in one of the dialog boxes. According to the output file, lets say 6 is read in the file. I then have to make 6 Buttons in that Dialog box. the number 6 could change, so I would like to know how to make it dynamic. Any ideas? Ehsan Behboudi
-
Hi, In my application, MDI, I have to read an output file in one of the dialog boxes. According to the output file, lets say 6 is read in the file. I then have to make 6 Buttons in that Dialog box. the number 6 could change, so I would like to know how to make it dynamic. Any ideas? Ehsan Behboudi
Just use a std::vector of CButtons.
std::vector<CButton> m_Buttons;
ifstream inFile;
char buff[1024] = {0};
CString szBuff;inFile.open("YourFile.txt");
while !inFile.eof())
{
inFile.getline(buff, sizeof(buff), chDelim);
szBuff = buff;
m_Buttons.push_back(CButton());
if(!m_Buttons.back().Create(static_cast<const char*>(szBuff), STYLEFLAGS, rectforbutton, this, uiSomeID))
TRACE("Error creating button");
m_Buttons.back().ShowWindow(SW_SHOW);}
inFile.close();
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb