i
i
i
i
i
i
i
i
19.4. Example Implementations 507
class MainUIWindow : public CDialog {
Model *TheModel; // The application State (Figure 11)
LPDIRECT3D9 TheGHC; // This is the Graphics Hardware Context
CWndD3D *LargeView; // These are View/Controller pairs that understand drawing
CWndD3D *SmallView; // with D3D (GDC) and UI element events (controller)
CSliderCtrl XSlider, YSlider; // These are the GUI elements
CStringEcho StatusEcho;
void OnTimer(); // Override the Timer service function
void OnHScroll( …); // Override the Scroll bar service function
};
Figure 19.25. MainUIWindow based on Microsoft Direct3D and MFC.
also supports interactive designing of the GUI element layout in (B), an area rep-
resenting the application window. Although the GUI builder interfaces operate
differently, we observe that in (C), the MFC resource editor also supports the
definition/modification of the physical appearance of GUI elements. However,
unlike Fluid, the MFC resource editor is tightly integrated with the rest of the
development environment. In this case, a developer can register for event ser-
vices by inheriting or overriding appropriate service routines. The MFC resource
editor automatically inserts code fragments into the application source code sys-
tem. To support this functionality, the application source code organization is
governed/shared with the GUI builder; the application developer is not entirely
free to rename files/classes and/or to re-organize implementation source code file
system structure. MFC implements internal direct code modification for event
service linkage, as described in Section 19.4.1.
Figure 19.25 shows the MainUIWindow implementation with Direct3D and
MFC. In this implementation, graphics operations are performed through Di-
rect3D while user interface operations are supported by MFC. Once again, The-
Model is the application state as detailed in Figure 19.11. LPDIRECT3D9is
the Graphics Hardware Context (GHC) interface object. This object is created
and initialized in the MainUIWindow constructor (not shown here). The two
CWndD3D objects are defined to support drawing with Direct3D. We notice that
one major difference between Figure 19.25 and Figure 19.22 is in the GUI ele-
ment support. In Figure 19.25, we see that the GUI element objects (e.g., XSlider)
and the corresponding service routines (e.g., OnHScroll()) are integrated into the
MainUIWindow object. This is in contrast to the solution shown in Figure 19.22
where GUI elements are grouped into a separate object (e.g., the UserInterface
object) with callback event service registrations. As discussed in Section 19.2.4,
MFC is an example of a large commercial GUI API, where many event services
are registered based on object-oriented function overrides (e.g., the OnHScroll()
and OnTimer() functions).