MouseEventsInViews
MouseEventsInViews is a sample that is essentially the same as
KeyEventsInViews, except that it uses mouse-button up and down events.
It illustrates how to query the mouse button state and get the event
location in global coordinates.
Running the sample
Execute MouseInputInViewsSApp. Click any mouse button
in one of the views. The view reports the location of the mouse click.
Files and classes
TMouseInputView is defined in MouseInputView.h and
MouseInputView.C. It derives from TContentView, which derives from
MEventTarget, so does not have to mix this in directly. It also mixes
in MMouseEventHandler, so that it can receive mouse events. It
overrides MouseButtonDown and MouseButtonUp to record the button
number, change (down or up), and location in global coordinates of the
event, and displays this information in its DrawContents member
function.
Notes
The MEventTarget must be registered with a TStandardEventReceiver.
Fortunately, the view system provides one for you to use. This sample
view connects to the event receiver in HandleAfterAddedToViewRoot, and
disconnects from it in HandleBeforeRemovedFromViewRoot.
Clicking the mouse outside the view hierarchy causes the event
receiver associated with our views to surrender the input focus, and
thus stop receiving events. So if you click down outside the window
containing a view, move the mouse to the view, and release the mouse
there, the view doesn't receive the event. Notice that clicking in a
view within the same window works as expected.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.