Graphics Reference
In-Depth Information
As we continue to program with GUI APIs, we will begin to encounter repeated
patterns of working with multiple GUI element types. For example, we will find
ourselves constantly working with slider bars that require the numeric echoing
functionality. The next few tutorials demonstrate how we can customize and/or
organize our interface with the GUI API to better support programming in a mod-
erately complex development environment.
Tutorial 2.6. The SliderCtrlWithEcho Class
Tutorial 2.6.
Project Name
MFC _ SliderCtrlWithEcho
Goal. Demonstrate that when appropriate, we should apply knowledge
from previous programming classes and define/customize new GUI ele-
ment classes. In most cases, this will ease the programming effort and
increase readability/maintainability of our system.
Approach. Customize GUI behavior by creating new GUI element types.
We will customize slider bar functionality to define a new slider bar type
that supports a numeric echo area.
Figure 2.10 is a screenshot of running Tutorial 2.6. Notice that the application
behaves identically to that of Tutorial 2.5. In this case, the only difference be-
tween these two applications is the support for the two slider bars. When we
compare the source code of the two tutorials, we see one extra class in Tuto-
rial 2.6: the SliderCtrlWithEcho.cpp/.h files.
Figure 2.10.
Tutorial
2.6.
This new class extends the
MFC CSliderCtrl class in two ways.
1. Slider bar range. CSliderCtrl only supports integer values. CSlider
CtrlWithEcho presents a floating-point range with 10 5 unique positions.
2. Numeric echo area. It is convenient, and often important, for the user to
know the exact numeric value of the slider bar knob position. SliderCtrl
WithEcho supports the echoing of the bar knob numeric values.
Source code folders. For
readability, folders and sub-
folders (when appropriate) are
created in the Visual Studio
Solution Explorer to organize
source files according to their
corresponding functionality.
Listing 2.10 shows the definition of the CSliderCtrlWithEcho class. We can
see a simple public interface where the user can initialize, set, and get slider bar
values. We also see familiar declarations of service routines and control variables.
Initialize() is the only MFC-specific function where we must create and insert
an echo GUI element for the numeric display. The rest of the classes are fairly
straightforward, and you should explore the implementations.
Search WWH ::




Custom Search