.NET/Windows API for .NET

GetCursorPos - Mouse Pointer의 현재위치 반환

클리엘 2019. 7. 31. 13:55
728x90

GetCursorPos함수는 현재 화면상에서 Mouse Pointer의 위치를 반환합니다.

Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (ByRef lpPoint As POINTAPI) As Integer

- VB.NET 선언

Public Structure POINTAPI
        Public x As Integer
        Public y As Integer
End Structure

Dim pntapi As POINTAPI
GetCursorPos(pntapi)

pntapi.x
pntapi.y

- VB.NET 호출

[DllImport("user32.dll")]
public static extern int GetCursorPos(ref POINTAPI lpPoint);

- C# 선언

public struct POINTAPI {
            public int x;
            public int y;
};

POINTAPI pntapi = new POINTAPI();
GetCursorPos(ref pntapi);

pntapi.x
pntapi.y

- C# 호출

 

이 함수는 실행에 실패하는 경우 0값을 반환합니다.

728x90