By now, you should understand the first part of these functions. First, you update the
variables with the current values of the controls on the window. Next, you check the
value of the boolean variable attached to the appropriate check box. If the variable is
TRUE, you want to enable or show the control. If the variable if FALSE, you want to disable
or hide the control.
At this point, the code begins to be harder to understand. The first function, GetDlgItem,
is passed the ID of the control that you want to change. This function returns the object
for that control. You can call this function to retrieve the object for any of the controls on
the window while your application is running. The next part of each command is where
a member function of the control object is called. The second function is a member function
of the object returned by the first function. If you are not clear on how this works,
then you might want to check out Appendix A, “C++ Review,” to brush up on your C++.
The second functions in these calls, EnableWindow and ShowWindow, look like they
should be used on windows, not controls. Well, yes, they should be used on windows;
they happen to be members of the C Wnd class, which is an ancestor of the C Dialog class from which your C Day 2 Dlg class is inherited. It just so happens that, in Windows, all controls are themselves windows, completely separate from the window on which they are placed. This allows you to treat controls as windows and to call windows functions on them. In fact, all the control classes are inherited from the CWnd class, revealing their true nature as windows.
If you compile and run your application now, you can try the Enable and Show Message Action check boxes. They should work just fine, as shown in Figure 2.11.