Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › GetPhysicalCursorPos

GetPhysicalCursorPos

関数
カーソルの現在の物理画面座標を取得する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// USER32.dll
#include <windows.h>

BOOL GetPhysicalCursorPos(
    POINT* lpPoint
);

パラメーター

名前方向
lpPointPOINT*out

戻り値の型: BOOL

各言語での呼び出し定義

// USER32.dll
#include <windows.h>

BOOL GetPhysicalCursorPos(
    POINT* lpPoint
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetPhysicalCursorPos(
    IntPtr lpPoint   // POINT* out
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetPhysicalCursorPos(
    lpPoint As IntPtr   ' POINT* out
) As Boolean
End Function
' lpPoint : POINT* out
Declare PtrSafe Function GetPhysicalCursorPos Lib "user32" ( _
    ByVal lpPoint As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetPhysicalCursorPos = ctypes.windll.user32.GetPhysicalCursorPos
GetPhysicalCursorPos.restype = wintypes.BOOL
GetPhysicalCursorPos.argtypes = [
    ctypes.c_void_p,  # lpPoint : POINT* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
GetPhysicalCursorPos = Fiddle::Function.new(
  lib['GetPhysicalCursorPos'],
  [
    Fiddle::TYPE_VOIDP,  # lpPoint : POINT* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn GetPhysicalCursorPos(
        lpPoint: *mut POINT  // POINT* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true)]
public static extern bool GetPhysicalCursorPos(IntPtr lpPoint);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetPhysicalCursorPos' -Namespace Win32 -PassThru
# $api::GetPhysicalCursorPos(lpPoint)
#uselib "USER32.dll"
#func global GetPhysicalCursorPos "GetPhysicalCursorPos" sptr
; GetPhysicalCursorPos varptr(lpPoint)   ; 戻り値は stat
; lpPoint : POINT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global GetPhysicalCursorPos "GetPhysicalCursorPos" var
; res = GetPhysicalCursorPos(lpPoint)
; lpPoint : POINT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetPhysicalCursorPos(POINT* lpPoint)
#uselib "USER32.dll"
#cfunc global GetPhysicalCursorPos "GetPhysicalCursorPos" var
; res = GetPhysicalCursorPos(lpPoint)
; lpPoint : POINT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetPhysicalCursorPos = user32.NewProc("GetPhysicalCursorPos")
)

// lpPoint (POINT* out)
r1, _, err := procGetPhysicalCursorPos.Call(
	uintptr(lpPoint),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetPhysicalCursorPos(
  lpPoint: Pointer   // POINT* out
): BOOL; stdcall;
  external 'USER32.dll' name 'GetPhysicalCursorPos';
result := DllCall("USER32\GetPhysicalCursorPos"
    , "Ptr", lpPoint   ; POINT* out
    , "Int")   ; return: BOOL
●GetPhysicalCursorPos(lpPoint) = DLL("USER32.dll", "bool GetPhysicalCursorPos(void*)")
# 呼び出し: GetPhysicalCursorPos(lpPoint)
# lpPoint : POINT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。