Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

ClientToScreen (user32)
 
.
Summary
The ClientToScreen API converts the client-area coordinates of a specified point to screen coordinates.

C# Signature:

[DllImport("user32.dll")]
static extern bool ClientToScreen(IntPtr hWnd, ref POINT lpPoint);

VB Signature:

<DllImport("user32.dll")> _
Private Shared Function ClientToScreen(ByVal hWnd As IntPtr, ByRef lpPoint As POINT) As Boolean
Private Shared Function ClientToScreen(ByVal hWnd As IntPtr, ByRef lpPoint As Point) As Boolean
End Function

User-Defined Types:

POINT

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

    [DllImport("user32.dll")]
    static extern bool ClientToScreen(IntPtr hwnd, ref Point lpPoint);

    [DllImport("user32.dll")]
    static extern bool SetCursorPos(int X, int Y);

    public void MoveCursorOverButton(Button button)
    {
        IntPtr handle = IntPtr.Zero;
        Point point;
        int x = 0;
        int y = 0;
        int width = 0;
        int height = 0;
        bool coordinatesFound = false;

        if (button != null)
        {
        width = button.Size.Width;
        height = button.Size.Height;
        handle = button.Handle;
        }

        if ((width > 0) && (height > 0))
        {
        point = new Point();
        x = (width / 2);
        y = (height / 2);

        coordinatesFound = ClientToScreen(handle, ref point);

        if (coordinatesFound == true)
        {
            SetCursorPos(point.X + x, point.Y + y);
        }
        }
    }

Alternative Managed API:

Control.PointToScreen
Control.RectangleToScreen

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions