60 likes | 70 Views
Capturing the Mouse. A window procedure normally receives mouse messages only when the mouse cursor is positioned over the client or nonclient area of the window. A program might need to receive mouse messages when the mouse is outside the window.
E N D
Capturing the Mouse • A window procedure normally receives mouse messages only when the mouse cursor is positioned over the client or nonclient area of the window. A program might need to receive mouse messages when the mouse is outside the window. • Capturing the mouse is easier than baiting a mousetrap. You need only call • SetCapture (hwnd) ; • When you want to release the mouse, call • ReleaseCapture () ; • which will returns things to normal. • To avoid problems, your program should capture the mouse only when the button is depressed in your client area. You should release the capture when the button is released. Visit for more Learning Resources
you can determine if a mouse is present by using our • old friend the GetSystemMetrics function: fMouse = GetSystemMetrics (SM_MOUSEPRESENT) ; • To determine the number of buttons on the installed mouse, use cButtons = GetSystemMetrics (SM_CMOUSEBUTTONS) ; • return 0 if a mouse is not installed. Windows 98 the function returns 2 if a mouse is not installed. • The hot spot is the tip of the arrow. • The default cursor for a particular window is specified when • defining the window class structure, for instance: wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
Actions you take with mouse buttons: • • Clicking Pressing and releasing a mouse button. • Double−clicking Pressing and releasing a mouse button twice in quick succession. • • Dragging Moving the mouse while holding down a button.
Client−Area Mouse Messages • A window procedure receives mouse messages • whenever the mouse passes over the window or is • clicked within the window, even if the window is not active • or does not have the input focus. • Button Pressed Released Pressed (Second Click) • Left WM_LBUTTONDOWN WM_LBUTTONUP WM_LBUTTONDBLCLK • Middle WM_MBUTTONDOWN WM_MBUTTONUP WM_MBUTTONDBLCLK • Right WM_RBUTTONDOWN WM_RBUTTONUP WM_RBUTTONDBLCLK
The value of lParam contains the position of the mouse. • The low word is the x−coordinate, and the high word is the • y−coordinate relative to the upper left corner of the client area of the window. • x = LOWORD (lParam) ; • y = HIWORD (lParam) ; • The value of wParam indicates the state of the mouse buttons and the • Shift and Ctrl keys. • The MK prefix stands for "mouse key." • MK_LBUTTON • MK_MBUTTON • MK_RBUTTON • MK_SHIFT • MK_CONTROL
WM_LBUTTONDOWN CONNECT clears the client area. • WM_MOUSEMOVE If the left button is down, • CONNECT draws a black dot on the client area • at the mouse position and saves the coordinates. • WM_LBUTTONUP CONNECT connects every dot • shown in the client area to every other dot. • Sometimes this results in a pretty design, • sometimes in a dense blob. For more detail contact us