ホーム › UI.WindowsAndMessaging › DragObject
DragObject
関数オブジェクトのドラッグ操作を開始し処理する。
シグネチャ
// USER32.dll
#include <windows.h>
DWORD DragObject(
HWND hwndParent,
HWND hwndFrom,
DWORD fmt,
UINT_PTR data,
HCURSOR hcur // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwndParent | HWND | in | ドラッグ操作の親ウィンドウのハンドル。 |
| hwndFrom | HWND | in | ドラッグ元ウィンドウのハンドル。 |
| fmt | DWORD | in | ドラッグするオブジェクトのクリップボード形式。 |
| data | UINT_PTR | in | ドラッグするオブジェクトに関連するアプリ定義データ。 |
| hcur | HCURSOR | inoptional | ドラッグ中に表示するカーソルのハンドル。 |
戻り値の型: DWORD
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
DWORD DragObject(
HWND hwndParent,
HWND hwndFrom,
DWORD fmt,
UINT_PTR data,
HCURSOR hcur // optional
);[DllImport("USER32.dll", ExactSpelling = true)]
static extern uint DragObject(
IntPtr hwndParent, // HWND
IntPtr hwndFrom, // HWND
uint fmt, // DWORD
UIntPtr data, // UINT_PTR
IntPtr hcur // HCURSOR optional
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function DragObject(
hwndParent As IntPtr, ' HWND
hwndFrom As IntPtr, ' HWND
fmt As UInteger, ' DWORD
data As UIntPtr, ' UINT_PTR
hcur As IntPtr ' HCURSOR optional
) As UInteger
End Function' hwndParent : HWND
' hwndFrom : HWND
' fmt : DWORD
' data : UINT_PTR
' hcur : HCURSOR optional
Declare PtrSafe Function DragObject Lib "user32" ( _
ByVal hwndParent As LongPtr, _
ByVal hwndFrom As LongPtr, _
ByVal fmt As Long, _
ByVal data As LongPtr, _
ByVal hcur As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DragObject = ctypes.windll.user32.DragObject
DragObject.restype = wintypes.DWORD
DragObject.argtypes = [
wintypes.HANDLE, # hwndParent : HWND
wintypes.HANDLE, # hwndFrom : HWND
wintypes.DWORD, # fmt : DWORD
ctypes.c_size_t, # data : UINT_PTR
wintypes.HANDLE, # hcur : HCURSOR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
DragObject = Fiddle::Function.new(
lib['DragObject'],
[
Fiddle::TYPE_VOIDP, # hwndParent : HWND
Fiddle::TYPE_VOIDP, # hwndFrom : HWND
-Fiddle::TYPE_INT, # fmt : DWORD
Fiddle::TYPE_UINTPTR_T, # data : UINT_PTR
Fiddle::TYPE_VOIDP, # hcur : HCURSOR optional
],
-Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn DragObject(
hwndParent: *mut core::ffi::c_void, // HWND
hwndFrom: *mut core::ffi::c_void, // HWND
fmt: u32, // DWORD
data: usize, // UINT_PTR
hcur: *mut core::ffi::c_void // HCURSOR optional
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll")]
public static extern uint DragObject(IntPtr hwndParent, IntPtr hwndFrom, uint fmt, UIntPtr data, IntPtr hcur);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DragObject' -Namespace Win32 -PassThru
# $api::DragObject(hwndParent, hwndFrom, fmt, data, hcur)#uselib "USER32.dll"
#func global DragObject "DragObject" sptr, sptr, sptr, sptr, sptr
; DragObject hwndParent, hwndFrom, fmt, data, hcur ; 戻り値は stat
; hwndParent : HWND -> "sptr"
; hwndFrom : HWND -> "sptr"
; fmt : DWORD -> "sptr"
; data : UINT_PTR -> "sptr"
; hcur : HCURSOR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global DragObject "DragObject" sptr, sptr, int, sptr, sptr
; res = DragObject(hwndParent, hwndFrom, fmt, data, hcur)
; hwndParent : HWND -> "sptr"
; hwndFrom : HWND -> "sptr"
; fmt : DWORD -> "int"
; data : UINT_PTR -> "sptr"
; hcur : HCURSOR optional -> "sptr"; DWORD DragObject(HWND hwndParent, HWND hwndFrom, DWORD fmt, UINT_PTR data, HCURSOR hcur)
#uselib "USER32.dll"
#cfunc global DragObject "DragObject" intptr, intptr, int, intptr, intptr
; res = DragObject(hwndParent, hwndFrom, fmt, data, hcur)
; hwndParent : HWND -> "intptr"
; hwndFrom : HWND -> "intptr"
; fmt : DWORD -> "int"
; data : UINT_PTR -> "intptr"
; hcur : HCURSOR optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procDragObject = user32.NewProc("DragObject")
)
// hwndParent (HWND), hwndFrom (HWND), fmt (DWORD), data (UINT_PTR), hcur (HCURSOR optional)
r1, _, err := procDragObject.Call(
uintptr(hwndParent),
uintptr(hwndFrom),
uintptr(fmt),
uintptr(data),
uintptr(hcur),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DragObject(
hwndParent: THandle; // HWND
hwndFrom: THandle; // HWND
fmt: DWORD; // DWORD
data: NativeUInt; // UINT_PTR
hcur: THandle // HCURSOR optional
): DWORD; stdcall;
external 'USER32.dll' name 'DragObject';result := DllCall("USER32\DragObject"
, "Ptr", hwndParent ; HWND
, "Ptr", hwndFrom ; HWND
, "UInt", fmt ; DWORD
, "UPtr", data ; UINT_PTR
, "Ptr", hcur ; HCURSOR optional
, "UInt") ; return: DWORD●DragObject(hwndParent, hwndFrom, fmt, data, hcur) = DLL("USER32.dll", "dword DragObject(void*, void*, dword, int, void*)")
# 呼び出し: DragObject(hwndParent, hwndFrom, fmt, data, hcur)
# hwndParent : HWND -> "void*"
# hwndFrom : HWND -> "void*"
# fmt : DWORD -> "dword"
# data : UINT_PTR -> "int"
# hcur : HCURSOR optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn DragObject(
hwndParent: ?*anyopaque, // HWND
hwndFrom: ?*anyopaque, // HWND
fmt: u32, // DWORD
data: usize, // UINT_PTR
hcur: ?*anyopaque // HCURSOR optional
) callconv(std.os.windows.WINAPI) u32;proc DragObject(
hwndParent: pointer, # HWND
hwndFrom: pointer, # HWND
fmt: uint32, # DWORD
data: uint, # UINT_PTR
hcur: pointer # HCURSOR optional
): uint32 {.importc: "DragObject", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
uint DragObject(
void* hwndParent, // HWND
void* hwndFrom, // HWND
uint fmt, // DWORD
size_t data, // UINT_PTR
void* hcur // HCURSOR optional
);ccall((:DragObject, "USER32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{Cvoid}, UInt32, Csize_t, Ptr{Cvoid}),
hwndParent, hwndFrom, fmt, data, hcur)
# hwndParent : HWND -> Ptr{Cvoid}
# hwndFrom : HWND -> Ptr{Cvoid}
# fmt : DWORD -> UInt32
# data : UINT_PTR -> Csize_t
# hcur : HCURSOR optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DragObject(
void* hwndParent,
void* hwndFrom,
uint32_t fmt,
uintptr_t data,
void* hcur);
]]
local user32 = ffi.load("user32")
-- user32.DragObject(hwndParent, hwndFrom, fmt, data, hcur)
-- hwndParent : HWND
-- hwndFrom : HWND
-- fmt : DWORD
-- data : UINT_PTR
-- hcur : HCURSOR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const DragObject = lib.func('__stdcall', 'DragObject', 'uint32_t', ['void *', 'void *', 'uint32_t', 'uintptr_t', 'void *']);
// DragObject(hwndParent, hwndFrom, fmt, data, hcur)
// hwndParent : HWND -> 'void *'
// hwndFrom : HWND -> 'void *'
// fmt : DWORD -> 'uint32_t'
// data : UINT_PTR -> 'uintptr_t'
// hcur : HCURSOR optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
DragObject: { parameters: ["pointer", "pointer", "u32", "usize", "pointer"], result: "u32" },
});
// lib.symbols.DragObject(hwndParent, hwndFrom, fmt, data, hcur)
// hwndParent : HWND -> "pointer"
// hwndFrom : HWND -> "pointer"
// fmt : DWORD -> "u32"
// data : UINT_PTR -> "usize"
// hcur : HCURSOR optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DragObject(
void* hwndParent,
void* hwndFrom,
uint32_t fmt,
size_t data,
void* hcur);
C, "USER32.dll");
// $ffi->DragObject(hwndParent, hwndFrom, fmt, data, hcur);
// hwndParent : HWND
// hwndFrom : HWND
// fmt : DWORD
// data : UINT_PTR
// hcur : HCURSOR optional
// 構造体/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);
int DragObject(
Pointer hwndParent, // HWND
Pointer hwndFrom, // HWND
int fmt, // DWORD
long data, // UINT_PTR
Pointer hcur // HCURSOR optional
);
}@[Link("user32")]
lib LibUSER32
fun DragObject = DragObject(
hwndParent : Void*, # HWND
hwndFrom : Void*, # HWND
fmt : UInt32, # DWORD
data : LibC::SizeT, # UINT_PTR
hcur : Void* # HCURSOR optional
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DragObjectNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Uint32, UintPtr, Pointer<Void>);
typedef DragObjectDart = int Function(Pointer<Void>, Pointer<Void>, int, int, Pointer<Void>);
final DragObject = DynamicLibrary.open('USER32.dll')
.lookupFunction<DragObjectNative, DragObjectDart>('DragObject');
// hwndParent : HWND -> Pointer<Void>
// hwndFrom : HWND -> Pointer<Void>
// fmt : DWORD -> Uint32
// data : UINT_PTR -> UintPtr
// hcur : HCURSOR optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DragObject(
hwndParent: THandle; // HWND
hwndFrom: THandle; // HWND
fmt: DWORD; // DWORD
data: NativeUInt; // UINT_PTR
hcur: THandle // HCURSOR optional
): DWORD; stdcall;
external 'USER32.dll' name 'DragObject';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DragObject"
c_DragObject :: Ptr () -> Ptr () -> Word32 -> CUIntPtr -> Ptr () -> IO Word32
-- hwndParent : HWND -> Ptr ()
-- hwndFrom : HWND -> Ptr ()
-- fmt : DWORD -> Word32
-- data : UINT_PTR -> CUIntPtr
-- hcur : HCURSOR optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dragobject =
foreign "DragObject"
((ptr void) @-> (ptr void) @-> uint32_t @-> size_t @-> (ptr void) @-> returning uint32_t)
(* hwndParent : HWND -> (ptr void) *)
(* hwndFrom : HWND -> (ptr void) *)
(* fmt : DWORD -> uint32_t *)
(* data : UINT_PTR -> size_t *)
(* hcur : HCURSOR optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("DragObject" drag-object :convention :stdcall) :uint32
(hwnd-parent :pointer) ; HWND
(hwnd-from :pointer) ; HWND
(fmt :uint32) ; DWORD
(data :uint64) ; UINT_PTR
(hcur :pointer)) ; HCURSOR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DragObject = Win32::API::More->new('USER32',
'DWORD DragObject(HANDLE hwndParent, HANDLE hwndFrom, DWORD fmt, WPARAM data, HANDLE hcur)');
# my $ret = $DragObject->Call($hwndParent, $hwndFrom, $fmt, $data, $hcur);
# hwndParent : HWND -> HANDLE
# hwndFrom : HWND -> HANDLE
# fmt : DWORD -> DWORD
# data : UINT_PTR -> WPARAM
# hcur : HCURSOR optional -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。