Graphics Reference
In-Depth Information
Checkbox service routine : copy state from GUI element to control variable
void CTutorialDlg::OnBnClickedTimerControlSliders() {
A5: UpdateData( true );
}
Listing 2.9. (cont.)
Figure 2.9 is a screenshot of running Tutorial 2.5. Once again, this tutorial is very
similar to Tutorial 2.4. From the front-end user interface, the only difference is
the timer control (TC) checkbox located in the center of the application window.
In this case, if the TC is checked, the application will decrement both of the slider
bar's values one unit per second. When both slider bars have value zero, the
application will uncheck TC. At any point, the user can check/uncheck the TC
and change the slider bar values by adjusting the knobs on the slider bars. In this
way, both of the slider bars and the TC can be controlled by both the application
and the user.
Listing 2.9 highlights the changes in the TutorialDlg.h/.cpp files (from
that of Tutorial 2.4).
Figure 2.9.
Tutorial 2.5.
The “Timer Control” (TC) checkbox (A). The variable and the event ser-
vice function are declared at label A1, the variable m _ TimerCtrlSliders
becomes the control variable of IDC _ TIMER _ CONTROL _ SLIDERS (the check-
box GUI element) at label A2, the checkbox event is registered at label A3,
the TC value is initialized to TRUE at label A4, and the service function is
defined at label A5. At label A3, we see another example of event registra-
tion with a callback function.
It is interesting that the checkbox service routine at A5 only has a single
statement: UpdateData(TRUE) . When the user clicks on the TC checkbox,
UpdateData(FALSE) . Recall
from previous tutorials that
UpdateData() with a FALSE
parameter flushes control vari-
able values to the GUI ele-
ment.
the front-end GUI will automatically flip the state of the checkbox GUI
element. However, this information is not reflected in the control variable
m _ TimerCtrlSldiers . UpdateData() with the TRUE parameter sets the
control variable according to the state of the GUI element.
The application controls GUI in the timer service routine (B). On the
per-second timer event, the timer service routine first checks to ensure that
the sliders are under the control of the application with the if statement at
label B1. If the condition is true, at label B2, the slider bar positions are
polled and decremented accordingly. When both of the slider bars have
value zero, at label B3, the control variable for the TC checkbox is updated
and flushed to the front-end GUI element (with UpdateData(FALSE) ).
 
Search WWH ::




Custom Search