SHDoDragDrop
関数ドラッグ画像付きでドラッグ&ドロップ操作を実行する。
シグネチャ
// SHELL32.dll
#include <windows.h>
HRESULT SHDoDragDrop(
HWND hwnd, // optional
IDataObject* pdata,
IDropSource* pdsrc, // optional
DROPEFFECT dwEffect,
DROPEFFECT* pdwEffect
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwnd | HWND | inoptional | ドラッグ イメージの取得に使用するウィンドウのハンドル。この値は NULL にできます。詳細については「解説」を参照してください。 |
| pdata | IDataObject* | in | ドラッグされるデータを含むデータ オブジェクトの IDataObject インターフェイスへのポインター。 |
| pdsrc | IDropSource* | inoptional | IDropSource インターフェイスの実装へのポインター。これはドラッグ操作中にソースと通信するために使用されます。 Windows Vista 以降では、この値が NULL の場合、シェルが代わりにドロップ ソース オブジェクトを作成します。 |
| dwEffect | DROPEFFECT | in | ドラッグ アンド ドロップ操作でソースが許可する効果。最も重要な効果は、ドラッグ アンド ドロップ操作が移動を許可するかどうかです。指定可能な値の一覧については、DROPEFFECT を参照してください。 |
| pdwEffect | DROPEFFECT* | out | ドラッグ アンド ドロップ操作がソース データにどのように影響したかを示す値へのポインター。pdwEffect パラメーターは、操作がキャンセルされなかった場合にのみ設定されます。指定可能な値の一覧については、DROPEFFECT を参照してください。 |
戻り値の型: HRESULT
公式ドキュメント
ドラッグ アンド ドロップ操作を実行します。必要に応じたドラッグ ソースの作成や、ドラッグ イメージをサポートします。
戻り値
型: HRESULT
この関数は、標準の戻り値 E_OUTOFMEMORY に加えて、次の値をサポートします。
| 戻り値 | 説明 |
|---|---|
| ドラッグ アンド ドロップ操作が成功しました。 | |
| ドラッグ アンド ドロップ操作がキャンセルされました。 | |
|
予期しないエラーが発生しました。 |
解説(Remarks)
Windows Vista 以降では、データ オブジェクト pdtobj にドラッグ イメージがまだ格納されておらず、かつ hwnd で指定されたウィンドウからドラッグ イメージを取得できない場合、シェルは汎用的なドラッグ イメージを提供します。指定されたウィンドウからドラッグ イメージを取得できない原因としては、hwnd が NULL であるか、指定されたウィンドウが DI_GETDRAGIMAGE メッセージをサポートしていないことが考えられます。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
HRESULT SHDoDragDrop(
HWND hwnd, // optional
IDataObject* pdata,
IDropSource* pdsrc, // optional
DROPEFFECT dwEffect,
DROPEFFECT* pdwEffect
);[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int SHDoDragDrop(
IntPtr hwnd, // HWND optional
IntPtr pdata, // IDataObject*
IntPtr pdsrc, // IDropSource* optional
uint dwEffect, // DROPEFFECT
out uint pdwEffect // DROPEFFECT* out
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHDoDragDrop(
hwnd As IntPtr, ' HWND optional
pdata As IntPtr, ' IDataObject*
pdsrc As IntPtr, ' IDropSource* optional
dwEffect As UInteger, ' DROPEFFECT
<Out> ByRef pdwEffect As UInteger ' DROPEFFECT* out
) As Integer
End Function' hwnd : HWND optional
' pdata : IDataObject*
' pdsrc : IDropSource* optional
' dwEffect : DROPEFFECT
' pdwEffect : DROPEFFECT* out
Declare PtrSafe Function SHDoDragDrop Lib "shell32" ( _
ByVal hwnd As LongPtr, _
ByVal pdata As LongPtr, _
ByVal pdsrc As LongPtr, _
ByVal dwEffect As Long, _
ByRef pdwEffect As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHDoDragDrop = ctypes.windll.shell32.SHDoDragDrop
SHDoDragDrop.restype = ctypes.c_int
SHDoDragDrop.argtypes = [
wintypes.HANDLE, # hwnd : HWND optional
ctypes.c_void_p, # pdata : IDataObject*
ctypes.c_void_p, # pdsrc : IDropSource* optional
wintypes.DWORD, # dwEffect : DROPEFFECT
ctypes.c_void_p, # pdwEffect : DROPEFFECT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHDoDragDrop = Fiddle::Function.new(
lib['SHDoDragDrop'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND optional
Fiddle::TYPE_VOIDP, # pdata : IDataObject*
Fiddle::TYPE_VOIDP, # pdsrc : IDropSource* optional
-Fiddle::TYPE_INT, # dwEffect : DROPEFFECT
Fiddle::TYPE_VOIDP, # pdwEffect : DROPEFFECT* out
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn SHDoDragDrop(
hwnd: *mut core::ffi::c_void, // HWND optional
pdata: *mut core::ffi::c_void, // IDataObject*
pdsrc: *mut core::ffi::c_void, // IDropSource* optional
dwEffect: u32, // DROPEFFECT
pdwEffect: *mut u32 // DROPEFFECT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll")]
public static extern int SHDoDragDrop(IntPtr hwnd, IntPtr pdata, IntPtr pdsrc, uint dwEffect, out uint pdwEffect);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHDoDragDrop' -Namespace Win32 -PassThru
# $api::SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect)#uselib "SHELL32.dll"
#func global SHDoDragDrop "SHDoDragDrop" sptr, sptr, sptr, sptr, sptr
; SHDoDragDrop hwnd, pdata, pdsrc, dwEffect, varptr(pdwEffect) ; 戻り値は stat
; hwnd : HWND optional -> "sptr"
; pdata : IDataObject* -> "sptr"
; pdsrc : IDropSource* optional -> "sptr"
; dwEffect : DROPEFFECT -> "sptr"
; pdwEffect : DROPEFFECT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global SHDoDragDrop "SHDoDragDrop" sptr, sptr, sptr, int, var ; res = SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect) ; hwnd : HWND optional -> "sptr" ; pdata : IDataObject* -> "sptr" ; pdsrc : IDropSource* optional -> "sptr" ; dwEffect : DROPEFFECT -> "int" ; pdwEffect : DROPEFFECT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global SHDoDragDrop "SHDoDragDrop" sptr, sptr, sptr, int, sptr ; res = SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, varptr(pdwEffect)) ; hwnd : HWND optional -> "sptr" ; pdata : IDataObject* -> "sptr" ; pdsrc : IDropSource* optional -> "sptr" ; dwEffect : DROPEFFECT -> "int" ; pdwEffect : DROPEFFECT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT SHDoDragDrop(HWND hwnd, IDataObject* pdata, IDropSource* pdsrc, DROPEFFECT dwEffect, DROPEFFECT* pdwEffect) #uselib "SHELL32.dll" #cfunc global SHDoDragDrop "SHDoDragDrop" intptr, intptr, intptr, int, var ; res = SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect) ; hwnd : HWND optional -> "intptr" ; pdata : IDataObject* -> "intptr" ; pdsrc : IDropSource* optional -> "intptr" ; dwEffect : DROPEFFECT -> "int" ; pdwEffect : DROPEFFECT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT SHDoDragDrop(HWND hwnd, IDataObject* pdata, IDropSource* pdsrc, DROPEFFECT dwEffect, DROPEFFECT* pdwEffect) #uselib "SHELL32.dll" #cfunc global SHDoDragDrop "SHDoDragDrop" intptr, intptr, intptr, int, intptr ; res = SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, varptr(pdwEffect)) ; hwnd : HWND optional -> "intptr" ; pdata : IDataObject* -> "intptr" ; pdsrc : IDropSource* optional -> "intptr" ; dwEffect : DROPEFFECT -> "int" ; pdwEffect : DROPEFFECT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHDoDragDrop = shell32.NewProc("SHDoDragDrop")
)
// hwnd (HWND optional), pdata (IDataObject*), pdsrc (IDropSource* optional), dwEffect (DROPEFFECT), pdwEffect (DROPEFFECT* out)
r1, _, err := procSHDoDragDrop.Call(
uintptr(hwnd),
uintptr(pdata),
uintptr(pdsrc),
uintptr(dwEffect),
uintptr(pdwEffect),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SHDoDragDrop(
hwnd: THandle; // HWND optional
pdata: Pointer; // IDataObject*
pdsrc: Pointer; // IDropSource* optional
dwEffect: DWORD; // DROPEFFECT
pdwEffect: Pointer // DROPEFFECT* out
): Integer; stdcall;
external 'SHELL32.dll' name 'SHDoDragDrop';result := DllCall("SHELL32\SHDoDragDrop"
, "Ptr", hwnd ; HWND optional
, "Ptr", pdata ; IDataObject*
, "Ptr", pdsrc ; IDropSource* optional
, "UInt", dwEffect ; DROPEFFECT
, "Ptr", pdwEffect ; DROPEFFECT* out
, "Int") ; return: HRESULT●SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect) = DLL("SHELL32.dll", "int SHDoDragDrop(void*, void*, void*, dword, void*)")
# 呼び出し: SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect)
# hwnd : HWND optional -> "void*"
# pdata : IDataObject* -> "void*"
# pdsrc : IDropSource* optional -> "void*"
# dwEffect : DROPEFFECT -> "dword"
# pdwEffect : DROPEFFECT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shell32" fn SHDoDragDrop(
hwnd: ?*anyopaque, // HWND optional
pdata: ?*anyopaque, // IDataObject*
pdsrc: ?*anyopaque, // IDropSource* optional
dwEffect: u32, // DROPEFFECT
pdwEffect: [*c]u32 // DROPEFFECT* out
) callconv(std.os.windows.WINAPI) i32;proc SHDoDragDrop(
hwnd: pointer, # HWND optional
pdata: pointer, # IDataObject*
pdsrc: pointer, # IDropSource* optional
dwEffect: uint32, # DROPEFFECT
pdwEffect: ptr uint32 # DROPEFFECT* out
): int32 {.importc: "SHDoDragDrop", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
int SHDoDragDrop(
void* hwnd, // HWND optional
void* pdata, // IDataObject*
void* pdsrc, // IDropSource* optional
uint dwEffect, // DROPEFFECT
uint* pdwEffect // DROPEFFECT* out
);ccall((:SHDoDragDrop, "SHELL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
hwnd, pdata, pdsrc, dwEffect, pdwEffect)
# hwnd : HWND optional -> Ptr{Cvoid}
# pdata : IDataObject* -> Ptr{Cvoid}
# pdsrc : IDropSource* optional -> Ptr{Cvoid}
# dwEffect : DROPEFFECT -> UInt32
# pdwEffect : DROPEFFECT* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SHDoDragDrop(
void* hwnd,
void* pdata,
void* pdsrc,
uint32_t dwEffect,
uint32_t* pdwEffect);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect)
-- hwnd : HWND optional
-- pdata : IDataObject*
-- pdsrc : IDropSource* optional
-- dwEffect : DROPEFFECT
-- pdwEffect : DROPEFFECT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const SHDoDragDrop = lib.func('__stdcall', 'SHDoDragDrop', 'int32_t', ['void *', 'void *', 'void *', 'uint32_t', 'uint32_t *']);
// SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect)
// hwnd : HWND optional -> 'void *'
// pdata : IDataObject* -> 'void *'
// pdsrc : IDropSource* optional -> 'void *'
// dwEffect : DROPEFFECT -> 'uint32_t'
// pdwEffect : DROPEFFECT* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
SHDoDragDrop: { parameters: ["pointer", "pointer", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect)
// hwnd : HWND optional -> "pointer"
// pdata : IDataObject* -> "pointer"
// pdsrc : IDropSource* optional -> "pointer"
// dwEffect : DROPEFFECT -> "u32"
// pdwEffect : DROPEFFECT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SHDoDragDrop(
void* hwnd,
void* pdata,
void* pdsrc,
uint32_t dwEffect,
uint32_t* pdwEffect);
C, "SHELL32.dll");
// $ffi->SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect);
// hwnd : HWND optional
// pdata : IDataObject*
// pdsrc : IDropSource* optional
// dwEffect : DROPEFFECT
// pdwEffect : DROPEFFECT* out
// 構造体/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 Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class);
int SHDoDragDrop(
Pointer hwnd, // HWND optional
Pointer pdata, // IDataObject*
Pointer pdsrc, // IDropSource* optional
int dwEffect, // DROPEFFECT
IntByReference pdwEffect // DROPEFFECT* out
);
}@[Link("shell32")]
lib LibSHELL32
fun SHDoDragDrop = SHDoDragDrop(
hwnd : Void*, # HWND optional
pdata : Void*, # IDataObject*
pdsrc : Void*, # IDropSource* optional
dwEffect : UInt32, # DROPEFFECT
pdwEffect : UInt32* # DROPEFFECT* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SHDoDragDropNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef SHDoDragDropDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, Pointer<Uint32>);
final SHDoDragDrop = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<SHDoDragDropNative, SHDoDragDropDart>('SHDoDragDrop');
// hwnd : HWND optional -> Pointer<Void>
// pdata : IDataObject* -> Pointer<Void>
// pdsrc : IDropSource* optional -> Pointer<Void>
// dwEffect : DROPEFFECT -> Uint32
// pdwEffect : DROPEFFECT* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHDoDragDrop(
hwnd: THandle; // HWND optional
pdata: Pointer; // IDataObject*
pdsrc: Pointer; // IDropSource* optional
dwEffect: DWORD; // DROPEFFECT
pdwEffect: Pointer // DROPEFFECT* out
): Integer; stdcall;
external 'SHELL32.dll' name 'SHDoDragDrop';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHDoDragDrop"
c_SHDoDragDrop :: Ptr () -> Ptr () -> Ptr () -> Word32 -> Ptr Word32 -> IO Int32
-- hwnd : HWND optional -> Ptr ()
-- pdata : IDataObject* -> Ptr ()
-- pdsrc : IDropSource* optional -> Ptr ()
-- dwEffect : DROPEFFECT -> Word32
-- pdwEffect : DROPEFFECT* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shdodragdrop =
foreign "SHDoDragDrop"
((ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* hwnd : HWND optional -> (ptr void) *)
(* pdata : IDataObject* -> (ptr void) *)
(* pdsrc : IDropSource* optional -> (ptr void) *)
(* dwEffect : DROPEFFECT -> uint32_t *)
(* pdwEffect : DROPEFFECT* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("SHDoDragDrop" shdo-drag-drop :convention :stdcall) :int32
(hwnd :pointer) ; HWND optional
(pdata :pointer) ; IDataObject*
(pdsrc :pointer) ; IDropSource* optional
(dw-effect :uint32) ; DROPEFFECT
(pdw-effect :pointer)) ; DROPEFFECT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHDoDragDrop = Win32::API::More->new('SHELL32',
'int SHDoDragDrop(HANDLE hwnd, LPVOID pdata, LPVOID pdsrc, DWORD dwEffect, LPVOID pdwEffect)');
# my $ret = $SHDoDragDrop->Call($hwnd, $pdata, $pdsrc, $dwEffect, $pdwEffect);
# hwnd : HWND optional -> HANDLE
# pdata : IDataObject* -> LPVOID
# pdsrc : IDropSource* optional -> LPVOID
# dwEffect : DROPEFFECT -> DWORD
# pdwEffect : DROPEFFECT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。