Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 5: The Document/View Architecture Visual C++ and MFC Fundamentals


MK_MBUTTON The middle mouse button is down
MK_RBUTTON The right mouse button is down
MK_SHIFT A Shift key was held down when the user double-clicked

The point argument specifies the location of the mouse pointer in x (horizontal) and y
(vertical) coordinates.

4.5.5 Mouse Moving


After pressing one of the mouse buttons, depending on the requirement, the use may not
need to immediately release the button. Another action performed with the mouse
consists of clicking and holding the mouse button down, then dragging in a chosen
direction. This action refers to the mouse moving. When this is done a
WM_MOUSEMOVE message is sent. Its syntax is:

afx_msg void OnMouseMove(UINT nFlags, CPoint point);

The nFlags argument specifies what button is held down or what key is pressed in
combination with the button that is held down while the mouse pointer is moving. This
argument can have one of the following values:

Value While the mouse is moving
MK_CONTROL A Ctrl key is held down
MK_LBUTTON The left mouse button is down
MK_MBUTTON The middle mouse button is down
MK_RBUTTON The right mouse button is down
MK_SHIFT A Shift key was held down

The point argument specifies the current location of the mouse pointer in x (horizontal)
and y (vertical) coordinates at the time the message is captured.

4.6 Anytime Messages.......................................................................................


4.6.1 Introduction...........................................................................................


The messages we have used so far belong to specific events generated at a particular time
by a window. Sometimes in the middle of doing something, you may want to send a
message regardless of what is going on. This is made possible by a function called
SendMessage(). Actually, there are two SendMessage() versions available.

The Win32 API version of the SendMessage() function has the following syntax:

LRESULT SendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

The MFC version is carried by the CWnd class and declared as follows:

LRESULT SendMessage(UINT Msg, WPARAM wParam, LPARAM lParam);

Because the Win32 version is considered global, if you want to use it, you must precede
it with the scope access operator "::" as in:

::SendMessage(WhatToDo);
Free download pdf