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

SetCursor

関数
現在のマウスカーソルの形状を設定する。
DLLUSER32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HCURSOR SetCursor(
    HCURSOR hCursor   // optional
);

パラメーター

名前方向
hCursorHCURSORinoptional

戻り値の型: HCURSOR

各言語での呼び出し定義

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

HCURSOR SetCursor(
    HCURSOR hCursor   // optional
);
[DllImport("USER32.dll", ExactSpelling = true)]
static extern IntPtr SetCursor(
    IntPtr hCursor   // HCURSOR optional
);
<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function SetCursor(
    hCursor As IntPtr   ' HCURSOR optional
) As IntPtr
End Function
' hCursor : HCURSOR optional
Declare PtrSafe Function SetCursor Lib "user32" ( _
    ByVal hCursor As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetCursor = ctypes.windll.user32.SetCursor
SetCursor.restype = ctypes.c_void_p
SetCursor.argtypes = [
    wintypes.HANDLE,  # hCursor : HCURSOR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
SetCursor = Fiddle::Function.new(
  lib['SetCursor'],
  [
    Fiddle::TYPE_VOIDP,  # hCursor : HCURSOR optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "user32")]
extern "system" {
    fn SetCursor(
        hCursor: *mut core::ffi::c_void  // HCURSOR optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll")]
public static extern IntPtr SetCursor(IntPtr hCursor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetCursor' -Namespace Win32 -PassThru
# $api::SetCursor(hCursor)
#uselib "USER32.dll"
#func global SetCursor "SetCursor" sptr
; SetCursor hCursor   ; 戻り値は stat
; hCursor : HCURSOR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global SetCursor "SetCursor" sptr
; res = SetCursor(hCursor)
; hCursor : HCURSOR optional -> "sptr"
; HCURSOR SetCursor(HCURSOR hCursor)
#uselib "USER32.dll"
#cfunc global SetCursor "SetCursor" intptr
; res = SetCursor(hCursor)
; hCursor : HCURSOR optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procSetCursor = user32.NewProc("SetCursor")
)

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