Win32 API 日本語リファレンス
ホームUI.Input.KeyboardAndMouse › SetCapture

SetCapture

関数
指定ウィンドウにマウス入力をキャプチャさせる。
DLLUSER32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HWND SetCapture(
    HWND hWnd
);

パラメーター

名前方向
hWndHWNDin

戻り値の型: HWND

各言語での呼び出し定義

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

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

SetCapture = ctypes.windll.user32.SetCapture
SetCapture.restype = ctypes.c_void_p
SetCapture.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
]
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procSetCapture = user32.NewProc("SetCapture")
)

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