ホーム › UI.Input.KeyboardAndMouse › DragDetect
DragDetect
関数ユーザーがドラッグ操作を開始したかを検出する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL DragDetect(
HWND hwnd,
POINT pt
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwnd | HWND | in | マウス入力を受け取るウィンドウへのハンドル。 |
| pt | POINT | in | マウスの初期位置(スクリーン座標)。この点を使用してドラッグ矩形の座標が決定されます。 |
戻り値の型: BOOL
公式ドキュメント
マウスをキャプチャし、ユーザーが左ボタンを離す、ESC キーを押す、または指定された点を中心とするドラッグ矩形の外側へマウスを移動するまで、その動きを追跡します。
戻り値
Type: BOOL
ユーザーが左ボタンを押したままドラッグ矩形の外側へマウスを移動した場合、戻り値は 0 以外になります。
ユーザーが左ボタンを押したままドラッグ矩形の外側へマウスを移動しなかった場合、戻り値は 0 になります。
解説(Remarks)
ドラッグ矩形のシステムメトリックは構成可能であり、より大きい、または小さいドラッグ矩形を設定できます。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
BOOL DragDetect(
HWND hwnd,
POINT pt
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", ExactSpelling = true)]
static extern bool DragDetect(
IntPtr hwnd, // HWND
POINT pt // POINT
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function DragDetect(
hwnd As IntPtr, ' HWND
pt As POINT ' POINT
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hwnd : HWND
' pt : POINT
Declare PtrSafe Function DragDetect Lib "user32" ( _
ByVal hwnd As LongPtr, _
ByVal pt As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DragDetect = ctypes.windll.user32.DragDetect
DragDetect.restype = wintypes.BOOL
DragDetect.argtypes = [
wintypes.HANDLE, # hwnd : HWND
POINT, # pt : POINT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
DragDetect = Fiddle::Function.new(
lib['DragDetect'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND
Fiddle::TYPE_VOIDP, # pt : POINT
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn DragDetect(
hwnd: *mut core::ffi::c_void, // HWND
pt: POINT // POINT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll")]
public static extern bool DragDetect(IntPtr hwnd, POINT pt);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DragDetect' -Namespace Win32 -PassThru
# $api::DragDetect(hwnd, pt)#uselib "USER32.dll"
#func global DragDetect "DragDetect" sptr, sptr
; DragDetect hwnd, pt ; 戻り値は stat
; hwnd : HWND -> "sptr"
; pt : POINT -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global DragDetect "DragDetect" sptr, int
; res = DragDetect(hwnd, pt)
; hwnd : HWND -> "sptr"
; pt : POINT -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。; BOOL DragDetect(HWND hwnd, POINT pt)
#uselib "USER32.dll"
#cfunc global DragDetect "DragDetect" intptr, int
; res = DragDetect(hwnd, pt)
; hwnd : HWND -> "intptr"
; pt : POINT -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procDragDetect = user32.NewProc("DragDetect")
)
// hwnd (HWND), pt (POINT)
r1, _, err := procDragDetect.Call(
uintptr(hwnd),
uintptr(pt),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction DragDetect(
hwnd: THandle; // HWND
pt: POINT // POINT
): BOOL; stdcall;
external 'USER32.dll' name 'DragDetect';result := DllCall("USER32\DragDetect"
, "Ptr", hwnd ; HWND
, "Ptr", pt ; POINT
, "Int") ; return: BOOL●DragDetect(hwnd, pt) = DLL("USER32.dll", "bool DragDetect(void*, void*)")
# 呼び出し: DragDetect(hwnd, pt)
# hwnd : HWND -> "void*"
# pt : POINT -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn DragDetect(
hwnd: ?*anyopaque, // HWND
pt: POINT // POINT
) callconv(std.os.windows.WINAPI) i32;proc DragDetect(
hwnd: pointer, # HWND
pt: POINT # POINT
): int32 {.importc: "DragDetect", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int DragDetect(
void* hwnd, // HWND
POINT pt // POINT
);ccall((:DragDetect, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, POINT),
hwnd, pt)
# hwnd : HWND -> Ptr{Cvoid}
# pt : POINT -> POINT
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t DragDetect(
void* hwnd,
POINT pt);
]]
local user32 = ffi.load("user32")
-- user32.DragDetect(hwnd, pt)
-- hwnd : HWND
-- pt : POINT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const DragDetect = lib.func('__stdcall', 'DragDetect', 'int32_t', ['void *', 'POINT']);
// DragDetect(hwnd, pt)
// hwnd : HWND -> 'void *'
// pt : POINT -> 'POINT'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
DragDetect: { parameters: ["pointer", "buffer"], result: "i32" },
});
// lib.symbols.DragDetect(hwnd, pt)
// hwnd : HWND -> "pointer"
// pt : POINT -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t DragDetect(
void* hwnd,
POINT pt);
C, "USER32.dll");
// $ffi->DragDetect(hwnd, pt);
// hwnd : HWND
// pt : POINT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class);
boolean DragDetect(
Pointer hwnd, // HWND
POINT /* extends Structure (by value) */ pt // POINT
);
}@[Link("user32")]
lib LibUSER32
fun DragDetect = DragDetect(
hwnd : Void*, # HWND
pt : POINT # POINT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DragDetectNative = Int32 Function(Pointer<Void>, POINT);
typedef DragDetectDart = int Function(Pointer<Void>, int);
final DragDetect = DynamicLibrary.open('USER32.dll')
.lookupFunction<DragDetectNative, DragDetectDart>('DragDetect');
// hwnd : HWND -> Pointer<Void>
// pt : POINT -> POINT
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DragDetect(
hwnd: THandle; // HWND
pt: POINT // POINT
): BOOL; stdcall;
external 'USER32.dll' name 'DragDetect';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DragDetect"
c_DragDetect :: Ptr () -> POINT -> IO CInt
-- hwnd : HWND -> Ptr ()
-- pt : POINT -> POINT
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。open Ctypes
open Foreign
let dragdetect =
foreign "DragDetect"
((ptr void) @-> POINT @-> returning int32_t)
(* hwnd : HWND -> (ptr void) *)
(* pt : POINT -> POINT *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("DragDetect" drag-detect :convention :stdcall) :int32
(hwnd :pointer) ; HWND
(pt (:struct point))) ; POINT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DragDetect = Win32::API::More->new('USER32',
'BOOL DragDetect(HANDLE hwnd, LPVOID pt)');
# my $ret = $DragDetect->Call($hwnd, $pt);
# hwnd : HWND -> HANDLE
# pt : POINT -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetSystemMetrics — 画面寸法やシステム構成要素の各種メトリクス値を取得する。
使用する型