GetCursorPos Function

Retrieves the cursor's position, in screen coordinates.

Syntax

BOOL GetCursorPos(      
    LPPOINT lpPoint );

Parameters

lpPoint
[out] Pointer to a POINT structure that receives the screen coordinates of the cursor.

Return Value

Returns nonzero if successful or zero otherwise. To get extended error information, call GetLastError.

Remarks

The cursor position is always specified in screen coordinates and is not affected by the mapping mode of the window that contains the cursor.

The calling process must have WINSTA_READATTRIBUTES access to the window station.

The input desktop must be the current desktop when you call GetCursorPos. Call OpenInputDesktop to determine whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned by OpenInputDesktop to switch to that desktop.

Example

For an example, see Using the Keyboard to Move the Cursor.

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 3.1

See Also

Tags :


Community Content

dmex
vb.net syntax
<DllImport("user32.dll")> _
Public Shared Function GetCursorPos(<[In], Out> ByVal pt As Point) As Boolean End Function

dmex
C# syntax
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out Point pt);
Tags : c# syntax

gartaud
GetCursorPos calls may fail in LAA applications
That implies that GetCursorPos should not be used by Large Address Aware applications.

GetCursorInfo seems to work fine, so consider using it instead.


To reproduce the problem:

On Vista x64:

Set the following registry value to 0x100000:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Memory Management\AllocationPreference
and reboot

Enable the Large Address Aware (LAA) flag for the application, e.g. editbin /LARGEADDRESSAWARE test.exe

Run the application

GetCursorPos will fail but GetCursorInfo seems to work fine.

Tags :

Page view tracker