Graphics Reference
In-Depth Information
event services are predefined by the MFC
CDialog
, and we override the
OnScroll()
functions to customize the services. The definition of event
service routines can be found at labels C3 and C7. Notice that if our appli-
cation has more than one horizontal scroll bar,
all
horizontal scroll events
will be serviced by the the same
OnHScroll()
function. This means, as
illustrated by the
if
statement in C3, that when servicing horizontal scroll
events, we must identify which of the scroll bars triggered the event. At
label C4, we call the
GetPos()
function on the control variable to obtain
the up-to-date knob value, which is updated in the echo control variable at
C5 and flushed to the corresponding GUI element at label C6.
Tutorial 2.4. Application-Defined Events
Tutorial 2.4.
Project Name
MFC
_
MouseAndTimer
•
Goal.
Experience events triggered by the application; experience working
with servicing events from the mouse.
•
Approach.
Work with GUI timer event; service all events from the mouse
and echo all relevant information to the application window.
Figure 2.8 is a screenshot of running Tutorial 2.4. The source code of this appli-
cation is based on that from Tutorial 2.3. When compared to the main application
window from Tutorial 2.3, we can see two extra sets of outputs.
•
Mouse echo.
When the mouse pointer is inside the application window,
this echo prints out the position of the mouse and the status (e.g., clicked)
of the mouse buttons.
Figure 2.8.
Tutorial 2.4.
•
Timer echo.
We will enable the timer alarm to trigger an event for our
application every second. This echo will print out the number of seconds
elapsed since we started running this application.
class
CTutorialDlg :
public
CDialog {
.
// removed content similar to that from
Listing 2.7 (Tutorial 2.3)
.
A1:
int
m
_
Seconds;
B1:
CString m
_
MouseEcho, m
_
TimerEcho;
Source file.
TutorialDlg.h/cpp
file in the
Source
and
Header
file folders of the
MFC
_
MouseAndTimer
project.
C1:
afx
_
msg void
OnTimer(UINT nIDEvent);
D1:
afx
_
msg void
OnLButtonDown(UINT nFlags, CPoint point);
afx
_
msg void
OnMouseMove(UINT nFlags, CPoint point);
afx
_
msg void
OnRButtonDown(UINT nFlags, CPoint point);
};
Listing 2.8.
CTutorialDlg
class (Tutorial 2.4).
Search WWH ::
Custom Search