An Introduction to Numerical Methods in C++, Revised Edition

A.3: Programming mouse buttons

A.3 Programming mouse buttons

In Windows much use is normally made of the mouse as an input device. The various mouse operations are defined by virtual functions with default values. However, the mouse buttons can be redefined to carry out whatever task we wish. We illustrate the technique by programming the right mouse button to create the message box of the last section. We begin by redefining the class TMyWindow, as follows:

   class TMyWindow : public TWindow {   private:         BOOL ButtonDown;   public:         TMyWindow (PTWindowsObject AParent, LPSTR ATitle):         TWindow (AParent, ATitle) { ButtonDown = FALSE; }         virtual void WMRButtonDown (RTMessage) = [WM_FIRST+WM_RBUTTONDOWN];         virtual void Paint (HDC PaintDC, PAINTSTRUCT &PaintInfo);   };

Note that we have included as a private data member the boolean variable ButtonDown, which is initialized to FALSE in the constructor. The other modification is the inclusion of the virtual function WMRButtonDown, initialized to the predetermined integer value WM_FIRST + WM_RBUTTONDOWN contained in square brackets. (Of course, these numbers are defined somewhere in the include files.) The prefix WM indicates that it is a function for processing a "Window Message", in this case a message sent by the mouse. Indeed, the function WMRButtonDown takes...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Computer Mice and Pointing Devices
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.