Capturing the Mouse A window procedure normally receives

  • Slides: 6
Download presentation
 • Capturing the Mouse • A window procedure normally receives mouse messages only

• 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 • Set. Capture (hwnd) ; When you want to release the mouse, call • Release. Capture () ; • 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

l l l you can determine if a mouse is present by using our

l l l you can determine if a mouse is present by using our old friend the Get. System. Metrics function: f. Mouse = Get. System. Metrics (SM_MOUSEPRESENT) ; To determine the number of buttons on the installed mouse, use c. Buttons = Get. System. Metrics (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 l defining the window class structure, for instance: wndclass. h. Cursor = Load. Cursor (NULL, IDC_ARROW) ; l

 • Actions you take with mouse buttons: • Clicking Pressing and releasing a

• 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

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 no • or does not have the input focus. • Button Pressed Released Pressed (Secon • Left WM_LBUTTONDOWN WM_LBUTTONUP WM_LBUTTO • Middle WM_MBUTTONDOWN WM_MBUTTONUP WM_MBUTT • Right WM_RBUTTONDOWN WM_RBUTTONUP WM_RBUTT

The value of l. Param contains the position of the mouse. The low word

The value of l. Param 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 wi • x = LOWORD (l. Param) ; • y = HIWORD (l. Param) ; The value of w. Param 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

• 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