troubleshooting Question

Need to disable all controls in MFC Dialog

Avatar of RWoodring
RWoodring asked on
C++System ProgrammingEditors IDEs
3 Comments1 Solution6202 ViewsLast Modified:
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++)

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros