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

ImageList_BeginDrag

関数
イメージリスト画像を用いたドラッグ操作を開始する。
DLLCOMCTL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

BOOL ImageList_BeginDrag(
    HIMAGELIST himlTrack,
    INT iTrack,
    INT dxHotspot,
    INT dyHotspot
);

パラメーター

名前方向説明
himlTrackHIMAGELISTinイメージリストへのハンドルです。
iTrackINTinドラッグするイメージのインデックスです。
dxHotspotINTinイメージの左上隅を基準とした、ドラッグ位置の x 座標です。
dyHotspotINTinイメージの左上隅を基準とした、ドラッグ位置の y 座標です。

戻り値の型: BOOL

公式ドキュメント

イメージのドラッグを開始します。(ImageList_BeginDrag)

戻り値

型: BOOL

成功した場合は 0 以外、それ以外の場合は 0 を返します。

解説(Remarks)

この関数は、ドラッグに使用する一時的なイメージリストを作成します。後続の WM_MOUSEMOVE メッセージに応じて、ImageList_DragMove 関数を使用してドラッグイメージを移動できます。ドラッグ操作を終了するには、ImageList_EndDrag 関数を使用します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL ImageList_BeginDrag(
    HIMAGELIST himlTrack,
    INT iTrack,
    INT dxHotspot,
    INT dyHotspot
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("COMCTL32.dll", ExactSpelling = true)]
static extern bool ImageList_BeginDrag(
    IntPtr himlTrack,   // HIMAGELIST
    int iTrack,   // INT
    int dxHotspot,   // INT
    int dyHotspot   // INT
);
<DllImport("COMCTL32.dll", ExactSpelling:=True)>
Public Shared Function ImageList_BeginDrag(
    himlTrack As IntPtr,   ' HIMAGELIST
    iTrack As Integer,   ' INT
    dxHotspot As Integer,   ' INT
    dyHotspot As Integer   ' INT
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' himlTrack : HIMAGELIST
' iTrack : INT
' dxHotspot : INT
' dyHotspot : INT
Declare PtrSafe Function ImageList_BeginDrag Lib "comctl32" ( _
    ByVal himlTrack As LongPtr, _
    ByVal iTrack As Long, _
    ByVal dxHotspot As Long, _
    ByVal dyHotspot As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ImageList_BeginDrag = ctypes.windll.comctl32.ImageList_BeginDrag
ImageList_BeginDrag.restype = wintypes.BOOL
ImageList_BeginDrag.argtypes = [
    ctypes.c_ssize_t,  # himlTrack : HIMAGELIST
    ctypes.c_int,  # iTrack : INT
    ctypes.c_int,  # dxHotspot : INT
    ctypes.c_int,  # dyHotspot : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('COMCTL32.dll')
ImageList_BeginDrag = Fiddle::Function.new(
  lib['ImageList_BeginDrag'],
  [
    Fiddle::TYPE_INTPTR_T,  # himlTrack : HIMAGELIST
    Fiddle::TYPE_INT,  # iTrack : INT
    Fiddle::TYPE_INT,  # dxHotspot : INT
    Fiddle::TYPE_INT,  # dyHotspot : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "comctl32")]
extern "system" {
    fn ImageList_BeginDrag(
        himlTrack: isize,  // HIMAGELIST
        iTrack: i32,  // INT
        dxHotspot: i32,  // INT
        dyHotspot: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("COMCTL32.dll")]
public static extern bool ImageList_BeginDrag(IntPtr himlTrack, int iTrack, int dxHotspot, int dyHotspot);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMCTL32_ImageList_BeginDrag' -Namespace Win32 -PassThru
# $api::ImageList_BeginDrag(himlTrack, iTrack, dxHotspot, dyHotspot)
#uselib "COMCTL32.dll"
#func global ImageList_BeginDrag "ImageList_BeginDrag" sptr, sptr, sptr, sptr
; ImageList_BeginDrag himlTrack, iTrack, dxHotspot, dyHotspot   ; 戻り値は stat
; himlTrack : HIMAGELIST -> "sptr"
; iTrack : INT -> "sptr"
; dxHotspot : INT -> "sptr"
; dyHotspot : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "COMCTL32.dll"
#cfunc global ImageList_BeginDrag "ImageList_BeginDrag" sptr, int, int, int
; res = ImageList_BeginDrag(himlTrack, iTrack, dxHotspot, dyHotspot)
; himlTrack : HIMAGELIST -> "sptr"
; iTrack : INT -> "int"
; dxHotspot : INT -> "int"
; dyHotspot : INT -> "int"
; BOOL ImageList_BeginDrag(HIMAGELIST himlTrack, INT iTrack, INT dxHotspot, INT dyHotspot)
#uselib "COMCTL32.dll"
#cfunc global ImageList_BeginDrag "ImageList_BeginDrag" intptr, int, int, int
; res = ImageList_BeginDrag(himlTrack, iTrack, dxHotspot, dyHotspot)
; himlTrack : HIMAGELIST -> "intptr"
; iTrack : INT -> "int"
; dxHotspot : INT -> "int"
; dyHotspot : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	comctl32 = windows.NewLazySystemDLL("COMCTL32.dll")
	procImageList_BeginDrag = comctl32.NewProc("ImageList_BeginDrag")
)

// himlTrack (HIMAGELIST), iTrack (INT), dxHotspot (INT), dyHotspot (INT)
r1, _, err := procImageList_BeginDrag.Call(
	uintptr(himlTrack),
	uintptr(iTrack),
	uintptr(dxHotspot),
	uintptr(dyHotspot),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function ImageList_BeginDrag(
  himlTrack: NativeInt;   // HIMAGELIST
  iTrack: Integer;   // INT
  dxHotspot: Integer;   // INT
  dyHotspot: Integer   // INT
): BOOL; stdcall;
  external 'COMCTL32.dll' name 'ImageList_BeginDrag';
result := DllCall("COMCTL32\ImageList_BeginDrag"
    , "Ptr", himlTrack   ; HIMAGELIST
    , "Int", iTrack   ; INT
    , "Int", dxHotspot   ; INT
    , "Int", dyHotspot   ; INT
    , "Int")   ; return: BOOL
●ImageList_BeginDrag(himlTrack, iTrack, dxHotspot, dyHotspot) = DLL("COMCTL32.dll", "bool ImageList_BeginDrag(int, int, int, int)")
# 呼び出し: ImageList_BeginDrag(himlTrack, iTrack, dxHotspot, dyHotspot)
# himlTrack : HIMAGELIST -> "int"
# iTrack : INT -> "int"
# dxHotspot : INT -> "int"
# dyHotspot : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "comctl32" fn ImageList_BeginDrag(
    himlTrack: isize, // HIMAGELIST
    iTrack: i32, // INT
    dxHotspot: i32, // INT
    dyHotspot: i32 // INT
) callconv(std.os.windows.WINAPI) i32;
proc ImageList_BeginDrag(
    himlTrack: int,  # HIMAGELIST
    iTrack: int32,  # INT
    dxHotspot: int32,  # INT
    dyHotspot: int32  # INT
): int32 {.importc: "ImageList_BeginDrag", stdcall, dynlib: "COMCTL32.dll".}
pragma(lib, "comctl32");
extern(Windows)
int ImageList_BeginDrag(
    ptrdiff_t himlTrack,   // HIMAGELIST
    int iTrack,   // INT
    int dxHotspot,   // INT
    int dyHotspot   // INT
);
ccall((:ImageList_BeginDrag, "COMCTL32.dll"), stdcall, Int32,
      (Int, Int32, Int32, Int32),
      himlTrack, iTrack, dxHotspot, dyHotspot)
# himlTrack : HIMAGELIST -> Int
# iTrack : INT -> Int32
# dxHotspot : INT -> Int32
# dyHotspot : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ImageList_BeginDrag(
    intptr_t himlTrack,
    int32_t iTrack,
    int32_t dxHotspot,
    int32_t dyHotspot);
]]
local comctl32 = ffi.load("comctl32")
-- comctl32.ImageList_BeginDrag(himlTrack, iTrack, dxHotspot, dyHotspot)
-- himlTrack : HIMAGELIST
-- iTrack : INT
-- dxHotspot : INT
-- dyHotspot : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('COMCTL32.dll');
const ImageList_BeginDrag = lib.func('__stdcall', 'ImageList_BeginDrag', 'int32_t', ['intptr_t', 'int32_t', 'int32_t', 'int32_t']);
// ImageList_BeginDrag(himlTrack, iTrack, dxHotspot, dyHotspot)
// himlTrack : HIMAGELIST -> 'intptr_t'
// iTrack : INT -> 'int32_t'
// dxHotspot : INT -> 'int32_t'
// dyHotspot : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("COMCTL32.dll", {
  ImageList_BeginDrag: { parameters: ["isize", "i32", "i32", "i32"], result: "i32" },
});
// lib.symbols.ImageList_BeginDrag(himlTrack, iTrack, dxHotspot, dyHotspot)
// himlTrack : HIMAGELIST -> "isize"
// iTrack : INT -> "i32"
// dxHotspot : INT -> "i32"
// dyHotspot : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ImageList_BeginDrag(
    intptr_t himlTrack,
    int32_t iTrack,
    int32_t dxHotspot,
    int32_t dyHotspot);
C, "COMCTL32.dll");
// $ffi->ImageList_BeginDrag(himlTrack, iTrack, dxHotspot, dyHotspot);
// himlTrack : HIMAGELIST
// iTrack : INT
// dxHotspot : INT
// dyHotspot : INT
// 構造体/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 Comctl32 extends StdCallLibrary {
    Comctl32 INSTANCE = Native.load("comctl32", Comctl32.class);
    boolean ImageList_BeginDrag(
        long himlTrack,   // HIMAGELIST
        int iTrack,   // INT
        int dxHotspot,   // INT
        int dyHotspot   // INT
    );
}
@[Link("comctl32")]
lib LibCOMCTL32
  fun ImageList_BeginDrag = ImageList_BeginDrag(
    himlTrack : LibC::SSizeT,   # HIMAGELIST
    iTrack : Int32,   # INT
    dxHotspot : Int32,   # INT
    dyHotspot : Int32   # INT
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ImageList_BeginDragNative = Int32 Function(IntPtr, Int32, Int32, Int32);
typedef ImageList_BeginDragDart = int Function(int, int, int, int);
final ImageList_BeginDrag = DynamicLibrary.open('COMCTL32.dll')
    .lookupFunction<ImageList_BeginDragNative, ImageList_BeginDragDart>('ImageList_BeginDrag');
// himlTrack : HIMAGELIST -> IntPtr
// iTrack : INT -> Int32
// dxHotspot : INT -> Int32
// dyHotspot : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ImageList_BeginDrag(
  himlTrack: NativeInt;   // HIMAGELIST
  iTrack: Integer;   // INT
  dxHotspot: Integer;   // INT
  dyHotspot: Integer   // INT
): BOOL; stdcall;
  external 'COMCTL32.dll' name 'ImageList_BeginDrag';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ImageList_BeginDrag"
  c_ImageList_BeginDrag :: CIntPtr -> Int32 -> Int32 -> Int32 -> IO CInt
-- himlTrack : HIMAGELIST -> CIntPtr
-- iTrack : INT -> Int32
-- dxHotspot : INT -> Int32
-- dyHotspot : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let imagelist_begindrag =
  foreign "ImageList_BeginDrag"
    (intptr_t @-> int32_t @-> int32_t @-> int32_t @-> returning int32_t)
(* himlTrack : HIMAGELIST -> intptr_t *)
(* iTrack : INT -> int32_t *)
(* dxHotspot : INT -> int32_t *)
(* dyHotspot : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library comctl32 (t "COMCTL32.dll"))
(cffi:use-foreign-library comctl32)

(cffi:defcfun ("ImageList_BeginDrag" image-list-begin-drag :convention :stdcall) :int32
  (himl-track :int64)   ; HIMAGELIST
  (i-track :int32)   ; INT
  (dx-hotspot :int32)   ; INT
  (dy-hotspot :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ImageList_BeginDrag = Win32::API::More->new('COMCTL32',
    'BOOL ImageList_BeginDrag(LPARAM himlTrack, int iTrack, int dxHotspot, int dyHotspot)');
# my $ret = $ImageList_BeginDrag->Call($himlTrack, $iTrack, $dxHotspot, $dyHotspot);
# himlTrack : HIMAGELIST -> LPARAM
# iTrack : INT -> int
# dxHotspot : INT -> int
# dyHotspot : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。