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

ClipCursor

関数
カーソルの移動範囲を指定矩形内に制限する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL ClipCursor(
    const RECT* lpRect   // optional
);

パラメーター

名前方向
lpRectRECT*inoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

ClipCursor = ctypes.windll.user32.ClipCursor
ClipCursor.restype = wintypes.BOOL
ClipCursor.argtypes = [
    ctypes.c_void_p,  # lpRect : RECT* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
ClipCursor = Fiddle::Function.new(
  lib['ClipCursor'],
  [
    Fiddle::TYPE_VOIDP,  # lpRect : RECT* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn ClipCursor(
        lpRect: *const RECT  // RECT* optional
    ) -> 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 ClipCursor(IntPtr lpRect);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_ClipCursor' -Namespace Win32 -PassThru
# $api::ClipCursor(lpRect)
#uselib "USER32.dll"
#func global ClipCursor "ClipCursor" sptr
; ClipCursor varptr(lpRect)   ; 戻り値は stat
; lpRect : RECT* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global ClipCursor "ClipCursor" var
; res = ClipCursor(lpRect)
; lpRect : RECT* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL ClipCursor(RECT* lpRect)
#uselib "USER32.dll"
#cfunc global ClipCursor "ClipCursor" var
; res = ClipCursor(lpRect)
; lpRect : RECT* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procClipCursor = user32.NewProc("ClipCursor")
)

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