Arrays of control
-
Hello, I'am doing a mfc dialog based program. In this one, I have a settings dialog box that should allow the user to select somethings through check boxes. The problem is that I've a lot of checkbox in this dialog (18 check box even more later!). I wanted to do array of controls in my settings dialog box (just like in VB). In order to do that I've short-circuited Class wizard to create an array of CButton member variables but I still have to enumerate each variable for each ID of each control with the DDX_Control(...) macro. There is also another problem. If the member variable is defined like this: CButton m_variable1; I can use the following statement: m_variable1.SetCheck(); But if I use the following declaration: CButton m_variable[18]; m_variable[0].SetCheck(); I'have a assertion failed. Can somebody give me a smart way to do such array of control? Thanks a lot. T. Varidel
-
Hello, I'am doing a mfc dialog based program. In this one, I have a settings dialog box that should allow the user to select somethings through check boxes. The problem is that I've a lot of checkbox in this dialog (18 check box even more later!). I wanted to do array of controls in my settings dialog box (just like in VB). In order to do that I've short-circuited Class wizard to create an array of CButton member variables but I still have to enumerate each variable for each ID of each control with the DDX_Control(...) macro. There is also another problem. If the member variable is defined like this: CButton m_variable1; I can use the following statement: m_variable1.SetCheck(); But if I use the following declaration: CButton m_variable[18]; m_variable[0].SetCheck(); I'have a assertion failed. Can somebody give me a smart way to do such array of control? Thanks a lot. T. Varidel
The smart alternative: A list box of checkboxes, via the CCheckListBox class. Regards, Alvaro
Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)
-
Hello, I'am doing a mfc dialog based program. In this one, I have a settings dialog box that should allow the user to select somethings through check boxes. The problem is that I've a lot of checkbox in this dialog (18 check box even more later!). I wanted to do array of controls in my settings dialog box (just like in VB). In order to do that I've short-circuited Class wizard to create an array of CButton member variables but I still have to enumerate each variable for each ID of each control with the DDX_Control(...) macro. There is also another problem. If the member variable is defined like this: CButton m_variable1; I can use the following statement: m_variable1.SetCheck(); But if I use the following declaration: CButton m_variable[18]; m_variable[0].SetCheck(); I'have a assertion failed. Can somebody give me a smart way to do such array of control? Thanks a lot. T. Varidel
You can do something like this: CButton* pButton[] = { &m_chk1, &m_chk2, &m_chk3, &m_chk4, }; pButton[n]->DoSomething(); or UINT array[] = { IDC_CONTROL1, IDC_CONTROL2, IDC_CONTROL3, IDC_CONTROL4, }; GetDlgItem(array[n)->DoSomething(); or use collection classes or STL; header file: vector m_wnds; then add your controls int OInitDialog: m_wnds.push_back(&m_chk1); m_wnds.push_back(&m_chk2; m_wnds.push_back(&m_chk3); m_wnds.push_back(&m_chk4); m_wnds.at(i)->DoSomething();
-
Hello, I'am doing a mfc dialog based program. In this one, I have a settings dialog box that should allow the user to select somethings through check boxes. The problem is that I've a lot of checkbox in this dialog (18 check box even more later!). I wanted to do array of controls in my settings dialog box (just like in VB). In order to do that I've short-circuited Class wizard to create an array of CButton member variables but I still have to enumerate each variable for each ID of each control with the DDX_Control(...) macro. There is also another problem. If the member variable is defined like this: CButton m_variable1; I can use the following statement: m_variable1.SetCheck(); But if I use the following declaration: CButton m_variable[18]; m_variable[0].SetCheck(); I'have a assertion failed. Can somebody give me a smart way to do such array of control? Thanks a lot. T. Varidel
Redesign your app. 18 checkboxes in one dialog is just too much. And use a listview, a tree with checkboxes, whatever.
I don't think this is a serious possesion, and the evil most likely comes from your hand. Colin J Davies, The Lounge