WM_LBUTTONDOWN Message

Platforms

Description & Usage

The WM_LBUTTONDOWN message tells a window that the left mouse button has been pressed while the cursor is inside the window's client area. The information sent with the message identifies the cursor postion relative to the window as well as the state of various modifier keys and mouse buttons. The target window's window procedure processes the message. When handling the message, the GET_X_LPARAM, GET_Y_LPARAM, and MAKEPOINTS macros can be used to unpack the coordinate information easily.

Return Value

WM_LBUTTONDOWN should always return 0.

Visual Basic-Specific Issues

It is not necessary to create a special hander for the WM_LBUTTONDOWN message. The MouseDown event handler provided by Visual Basic actually process WM_LBUTTONDOWN and unpacks some of the information passed with it for easier use.

Parameters

wParam
A combination of the following flags specifying which modifer keys, if any, are currently depressed:
MK_CONTROL
The Ctrl key is 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
The Shift key is down.
MK_XBUTTON1
Windows 2000: The first X button is down.
MK_XBUTTON2
Windows 2000: The second X button is down.
lParam
The (x,y) coordinates of the mouse cursor relative to the window. The low-order word contains the x-coordinate, and the high-order word contains the y-coordinate.

Constant Definitions

Const WM_LBUTTONDOWN = &H201
Const MK_CONTROL = &H8
Const MK_LBUTTON = &H1
Const MK_MBUTTON = &H10
Const MK_RBUTTON = &H2
Const MK_SHIFT = &H4
Const MK_XBUTTON1 = &H20
Const MK_XBUTTON2 = &H40

Example

' This code is licensed according to the terms and conditions listed here.

' Make window Form1 think that the left mouse button has been
' pressed in its center by sending the appropriate message to it.
Dim xcoord As Long, ycoord As Long  ' x and y coordinates of the faked cursor position
Dim packed As Long  ' the coordinates "packed" into a single 32-bit integer
Dim winrect As RECT  ' receives coordinates of the window
Dim retval As Long  ' return value

' First, get the coordinates of window Form1.
retval = GetWindowRect(Form1.hWnd, winrect)
' Use the coordinates to calculate the midpoint of Form1.
xcoord = (winrect.right - winrect.left) / 2
ycoord = (winrect.bottom - winrect.top) / 2
' Now pack the coordinates into the appropriate words of the value
packed = (ycoord * &H10000) + xcoord

' Make Form1 think the left mouse button was just pressed in that position.
retval = SendMessage(Form1.hWnd, WM_LBUTTONDOWN, ByVal CLng(MK_LBUTTON), ByVal packed)

See Also

WM_LBUTTONDBLCLK, WM_LBUTTONUP, WM_MBUTTONDOWN, WM_RBUTTONDOWN

Category

Mouse

Back to the Message list.
Back to the Reference section.


Last Modified: March 19, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/w/wm_lbuttondown.html