1 / 6

Capturing the Mouse

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.

karlal
Download Presentation

Capturing the Mouse

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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) ;

  3. 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.

  4. 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

  5. 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

  6. 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

More Related