Chapter Four

Basic Event Handling, Mapping Modes, and a Scrolling View

In Chapter 3, you saw how the Microsoft Foundation Class (MFC) Library application framework called the view class's virtual OnDraw function. Take a look at the online help for the MFC library now. If you look at the documentation for the CView class and its base class, CWnd, you'll see several hundred member functions. Functions whose names begin with On—such as OnKeyDown and OnLButtonUp—are member functions that the application framework calls in response to various Windows "events" such as keystrokes and mouse clicks.

Most of these application framework-called functions, such as OnKeyDown, aren't virtual functions and thus require more programming steps. This chapter explains how to use the Visual C++ ClassWizard to set up the message map structure necessary for connecting the application framework to your functions' code. You'll see the practical application of message map functions.

The first two examples use an ordinary CView class. In EX04A, you'll learn about the interaction between user-driven events and the OnDraw function. In EX04B, you'll see the effects of different Windows mapping modes.

More often than not, you'll want a scrolling view. The last example, EX04C, uses CScrollView in place of the CView base class. This allows the MFC library application framework to insert scroll bars and connect them to the view.