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

SHDoDragDrop

関数
ドラッグ画像付きでドラッグ&ドロップ操作を実行する。
DLLSHELL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT SHDoDragDrop(
    HWND hwnd,   // optional
    IDataObject* pdata,
    IDropSource* pdsrc,   // optional
    DROPEFFECT dwEffect,
    DROPEFFECT* pdwEffect
);

パラメーター

名前方向
hwndHWNDinoptional
pdataIDataObject*in
pdsrcIDropSource*inoptional
dwEffectDROPEFFECTin
pdwEffectDROPEFFECT*out

戻り値の型: HRESULT

各言語での呼び出し定義

// 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, 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, int
; res = SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect)
; hwnd : HWND optional -> "sptr"
; pdata : IDataObject* -> "sptr"
; pdsrc : IDropSource* optional -> "sptr"
; dwEffect : DROPEFFECT -> "int"
; pdwEffect : DROPEFFECT* out -> "int"
; HRESULT SHDoDragDrop(HWND hwnd, IDataObject* pdata, IDropSource* pdsrc, DROPEFFECT dwEffect, DROPEFFECT* pdwEffect)
#uselib "SHELL32.dll"
#cfunc global SHDoDragDrop "SHDoDragDrop" intptr, intptr, intptr, int, int
; res = SHDoDragDrop(hwnd, pdata, pdsrc, dwEffect, pdwEffect)
; hwnd : HWND optional -> "intptr"
; pdata : IDataObject* -> "intptr"
; pdsrc : IDropSource* optional -> "intptr"
; dwEffect : DROPEFFECT -> "int"
; pdwEffect : DROPEFFECT* out -> "int"
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   // HRESULT
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';
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)。