DragAcceptFiles
関数ウィンドウのドラッグ&ドロップ受け入れを設定する。
シグネチャ
// SHELL32.dll
#include <windows.h>
void DragAcceptFiles(
HWND hWnd,
BOOL fAccept
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | ドロップされたファイルを受け入れるかどうかを登録するウィンドウの識別子です。 |
| fAccept | BOOL | in | hWnd パラメーターで識別されるウィンドウがドロップされたファイルを受け入れるかどうかを示す値です。ドロップされたファイルを受け入れる場合は TRUE、受け入れを中止する場合は FALSE を指定します。 |
戻り値の型: void
公式ドキュメント
ウィンドウがドロップされたファイルを受け入れるかどうかを登録します。
解説(Remarks)
fAccept パラメーターを TRUE に設定して DragAcceptFiles を呼び出すアプリケーションは、ファイル マネージャーからの WM_DROPFILES メッセージを処理できることを表明したことになります。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
void DragAcceptFiles(
HWND hWnd,
BOOL fAccept
);[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern void DragAcceptFiles(
IntPtr hWnd, // HWND
bool fAccept // BOOL
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Sub DragAcceptFiles(
hWnd As IntPtr, ' HWND
fAccept As Boolean ' BOOL
)
End Sub' hWnd : HWND
' fAccept : BOOL
Declare PtrSafe Sub DragAcceptFiles Lib "shell32" ( _
ByVal hWnd As LongPtr, _
ByVal fAccept As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DragAcceptFiles = ctypes.windll.shell32.DragAcceptFiles
DragAcceptFiles.restype = None
DragAcceptFiles.argtypes = [
wintypes.HANDLE, # hWnd : HWND
wintypes.BOOL, # fAccept : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
DragAcceptFiles = Fiddle::Function.new(
lib['DragAcceptFiles'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
Fiddle::TYPE_INT, # fAccept : BOOL
],
Fiddle::TYPE_VOID)#[link(name = "shell32")]
extern "system" {
fn DragAcceptFiles(
hWnd: *mut core::ffi::c_void, // HWND
fAccept: i32 // BOOL
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll")]
public static extern void DragAcceptFiles(IntPtr hWnd, bool fAccept);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_DragAcceptFiles' -Namespace Win32 -PassThru
# $api::DragAcceptFiles(hWnd, fAccept)#uselib "SHELL32.dll"
#func global DragAcceptFiles "DragAcceptFiles" sptr, sptr
; DragAcceptFiles hWnd, fAccept
; hWnd : HWND -> "sptr"
; fAccept : BOOL -> "sptr"#uselib "SHELL32.dll"
#func global DragAcceptFiles "DragAcceptFiles" sptr, int
; DragAcceptFiles hWnd, fAccept
; hWnd : HWND -> "sptr"
; fAccept : BOOL -> "int"; void DragAcceptFiles(HWND hWnd, BOOL fAccept)
#uselib "SHELL32.dll"
#func global DragAcceptFiles "DragAcceptFiles" intptr, int
; DragAcceptFiles hWnd, fAccept
; hWnd : HWND -> "intptr"
; fAccept : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procDragAcceptFiles = shell32.NewProc("DragAcceptFiles")
)
// hWnd (HWND), fAccept (BOOL)
r1, _, err := procDragAcceptFiles.Call(
uintptr(hWnd),
uintptr(fAccept),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure DragAcceptFiles(
hWnd: THandle; // HWND
fAccept: BOOL // BOOL
); stdcall;
external 'SHELL32.dll' name 'DragAcceptFiles';result := DllCall("SHELL32\DragAcceptFiles"
, "Ptr", hWnd ; HWND
, "Int", fAccept ; BOOL
, "Int") ; return: void●DragAcceptFiles(hWnd, fAccept) = DLL("SHELL32.dll", "int DragAcceptFiles(void*, bool)")
# 呼び出し: DragAcceptFiles(hWnd, fAccept)
# hWnd : HWND -> "void*"
# fAccept : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shell32" fn DragAcceptFiles(
hWnd: ?*anyopaque, // HWND
fAccept: i32 // BOOL
) callconv(std.os.windows.WINAPI) void;proc DragAcceptFiles(
hWnd: pointer, # HWND
fAccept: int32 # BOOL
) {.importc: "DragAcceptFiles", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
void DragAcceptFiles(
void* hWnd, // HWND
int fAccept // BOOL
);ccall((:DragAcceptFiles, "SHELL32.dll"), stdcall, Cvoid,
(Ptr{Cvoid}, Int32),
hWnd, fAccept)
# hWnd : HWND -> Ptr{Cvoid}
# fAccept : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void DragAcceptFiles(
void* hWnd,
int32_t fAccept);
]]
local shell32 = ffi.load("shell32")
-- shell32.DragAcceptFiles(hWnd, fAccept)
-- hWnd : HWND
-- fAccept : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const DragAcceptFiles = lib.func('__stdcall', 'DragAcceptFiles', 'void', ['void *', 'int32_t']);
// DragAcceptFiles(hWnd, fAccept)
// hWnd : HWND -> 'void *'
// fAccept : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
DragAcceptFiles: { parameters: ["pointer", "i32"], result: "void" },
});
// lib.symbols.DragAcceptFiles(hWnd, fAccept)
// hWnd : HWND -> "pointer"
// fAccept : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void DragAcceptFiles(
void* hWnd,
int32_t fAccept);
C, "SHELL32.dll");
// $ffi->DragAcceptFiles(hWnd, fAccept);
// hWnd : HWND
// fAccept : BOOL
// 構造体/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);
void DragAcceptFiles(
Pointer hWnd, // HWND
boolean fAccept // BOOL
);
}@[Link("shell32")]
lib LibSHELL32
fun DragAcceptFiles = DragAcceptFiles(
hWnd : Void*, # HWND
fAccept : Int32 # BOOL
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DragAcceptFilesNative = Void Function(Pointer<Void>, Int32);
typedef DragAcceptFilesDart = void Function(Pointer<Void>, int);
final DragAcceptFiles = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<DragAcceptFilesNative, DragAcceptFilesDart>('DragAcceptFiles');
// hWnd : HWND -> Pointer<Void>
// fAccept : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure DragAcceptFiles(
hWnd: THandle; // HWND
fAccept: BOOL // BOOL
); stdcall;
external 'SHELL32.dll' name 'DragAcceptFiles';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DragAcceptFiles"
c_DragAcceptFiles :: Ptr () -> CInt -> IO ()
-- hWnd : HWND -> Ptr ()
-- fAccept : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dragacceptfiles =
foreign "DragAcceptFiles"
((ptr void) @-> int32_t @-> returning void)
(* hWnd : HWND -> (ptr void) *)
(* fAccept : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("DragAcceptFiles" drag-accept-files :convention :stdcall) :void
(h-wnd :pointer) ; HWND
(f-accept :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DragAcceptFiles = Win32::API::More->new('SHELL32',
'void DragAcceptFiles(HANDLE hWnd, BOOL fAccept)');
# my $ret = $DragAcceptFiles->Call($hWnd, $fAccept);
# hWnd : HWND -> HANDLE
# fAccept : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。