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

CreateCursor

関数
ANDマスクとXORマスクから新しいカーソルを作成する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

HCURSOR CreateCursor(
    HINSTANCE hInst,   // optional
    INT xHotSpot,
    INT yHotSpot,
    INT nWidth,
    INT nHeight,
    const void* pvANDPlane,
    const void* pvXORPlane
);

パラメーター

名前方向
hInstHINSTANCEinoptional
xHotSpotINTin
yHotSpotINTin
nWidthINTin
nHeightINTin
pvANDPlanevoid*in
pvXORPlanevoid*in

戻り値の型: HCURSOR

各言語での呼び出し定義

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

HCURSOR CreateCursor(
    HINSTANCE hInst,   // optional
    INT xHotSpot,
    INT yHotSpot,
    INT nWidth,
    INT nHeight,
    const void* pvANDPlane,
    const void* pvXORPlane
);
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateCursor(
    IntPtr hInst,   // HINSTANCE optional
    int xHotSpot,   // INT
    int yHotSpot,   // INT
    int nWidth,   // INT
    int nHeight,   // INT
    IntPtr pvANDPlane,   // void*
    IntPtr pvXORPlane   // void*
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateCursor(
    hInst As IntPtr,   ' HINSTANCE optional
    xHotSpot As Integer,   ' INT
    yHotSpot As Integer,   ' INT
    nWidth As Integer,   ' INT
    nHeight As Integer,   ' INT
    pvANDPlane As IntPtr,   ' void*
    pvXORPlane As IntPtr   ' void*
) As IntPtr
End Function
' hInst : HINSTANCE optional
' xHotSpot : INT
' yHotSpot : INT
' nWidth : INT
' nHeight : INT
' pvANDPlane : void*
' pvXORPlane : void*
Declare PtrSafe Function CreateCursor Lib "user32" ( _
    ByVal hInst As LongPtr, _
    ByVal xHotSpot As Long, _
    ByVal yHotSpot As Long, _
    ByVal nWidth As Long, _
    ByVal nHeight As Long, _
    ByVal pvANDPlane As LongPtr, _
    ByVal pvXORPlane As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateCursor = ctypes.windll.user32.CreateCursor
CreateCursor.restype = ctypes.c_void_p
CreateCursor.argtypes = [
    wintypes.HANDLE,  # hInst : HINSTANCE optional
    ctypes.c_int,  # xHotSpot : INT
    ctypes.c_int,  # yHotSpot : INT
    ctypes.c_int,  # nWidth : INT
    ctypes.c_int,  # nHeight : INT
    ctypes.POINTER(None),  # pvANDPlane : void*
    ctypes.POINTER(None),  # pvXORPlane : void*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procCreateCursor = user32.NewProc("CreateCursor")
)

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