When programming with VC / MFC, you often encounter the situation where you want to do the same operation simultaneously, especially if you want some controls to disable or hide certain controls. At this point you can generally have the following choices:
1. You can give each control to the control type variable, then operate one by one, which obviously occupies memory when the dialog class is instantiated, and the memory used to store member variables;
2. You can also get the form pointer of the control through the getDlgitem function to operate one by one, in addition to occupying the pointer, there is no doubt that the amount of code will increase when encountering too many controls;
3. You can use the pointer array to record all controls, usually to perform an initialization action to record the control to operate under the moving box start display, and then operate. In addition to the pointer space, this method encounters different types of transformation.
4. Of course, if you want to use the control array like VB, you can also be implemented in the VC, but mainly it is not suitable for different types of controls except for the occupancy space.
What is introduced here is that if two member functions comes with the dialog class, they are:
l CWnd :: getNextdlgtabItem Get "Next" TAB Item Control
l CWnd :: getNextdlgroupItem Get "Next" in a set of controls
note:
1. The "next" here is relatively, you can turn it into "Previous" through their parameters;
2. In the user, you should pay attention to the "tabstop" property of the control control must be hook or it must have a WS_TABSTOP style;
3. Use the latter function to make the control to operate in a group, the method is hook on the group attribute of the first control, the back is not hook;
4. When a batch of controls are enable (false) Next time, the next two functions is used, so it is necessary to recover their words again, and they must be recorded;
5. For detailed descriptions of the above two functions, please refer to MSDN.
Below is an example of calling applications:
CWND * PWNDCTRL = getdlgitem (idc_static1);
For (i = 0; i <11 && pwndctrl! = null; i )
{
PWNDCTRL-> EnableWindow (False);
PWndCtrl = getNextdlgTabItem (PWNDCTR);
}
The above code will disable 11 controls at the same time, and if you change GetNextdlgTabItem to getNextdlgroupItem, you will operate a set of controls.
Of course, because these two functions are members of the CWnd class, the controls on the non-dialog box or dynamically created controls are equally valid.