I have a dialog based MFC application (Visual Studio 2005) which serves as a user interface for a piece of equipment. Before any of the controls in the user interface are useful, the application must connect to the equipment through the network (using TCP sockets). To support this, I provided a CEdit box for a hostname, CEdit box for a port number, a CButton to connect and CButton to disconnect. These controls are on the main dialog along with all the controls that actually send information to the equipment.
What I want to do is to have a simple function which can disable every control in the dialog box and another one that will enable every control. My OnInitDialog() function would first disable ALL the controls and then enable the hostname, port, and connect button. After the user clicks the connect button and the network connection is established, ALL controls would be enabled and a few (like the connect button) would be disabled. I could do this with a long list of calls to EnableWindow, one for each control in my user interface, but I would like to make the enable/disable functions more generic.
I came up with 2 options for this, but do not know how to implement either one:
1) Is there some way I can get a list of IDC_ control ids dynamically at run time to step through in a loop like the following
List idList = SomeFunction() // Get a list of control objects
for(int k = 0; k < idList.length(); k++)
2) The other option I though of is that if all my IDC_ ids increment, I would only need to know the total number of items and I could do the following:
unsigned int cnt = SomeFunction(); // Get the total number of control objects
for(int k = 0; k < cnt; k++)