Win32 API 日本語リファレンス
ホームGraphics.Dwm › DwmRegisterThumbnail

DwmRegisterThumbnail

関数
ソースウィンドウのサムネイルを宛先ウィンドウに登録する。
DLLdwmapi.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT DwmRegisterThumbnail(
    HWND hwndDestination,
    HWND hwndSource,
    INT_PTR* phThumbnailId
);

パラメーター

名前方向説明
hwndDestinationHWNDinサムネイルを表示する側(宛先)のウィンドウハンドル。
hwndSourceHWNDinサムネイルとして描画する元ウィンドウのハンドル。
phThumbnailIdINT_PTR*out生成されたサムネイル登録ハンドルを受け取る出力先。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT DwmRegisterThumbnail(
    HWND hwndDestination,
    HWND hwndSource,
    INT_PTR* phThumbnailId
);
[DllImport("dwmapi.dll", ExactSpelling = true)]
static extern int DwmRegisterThumbnail(
    IntPtr hwndDestination,   // HWND
    IntPtr hwndSource,   // HWND
    out IntPtr phThumbnailId   // INT_PTR* out
);
<DllImport("dwmapi.dll", ExactSpelling:=True)>
Public Shared Function DwmRegisterThumbnail(
    hwndDestination As IntPtr,   ' HWND
    hwndSource As IntPtr,   ' HWND
    <Out> ByRef phThumbnailId As IntPtr   ' INT_PTR* out
) As Integer
End Function
' hwndDestination : HWND
' hwndSource : HWND
' phThumbnailId : INT_PTR* out
Declare PtrSafe Function DwmRegisterThumbnail Lib "dwmapi" ( _
    ByVal hwndDestination As LongPtr, _
    ByVal hwndSource As LongPtr, _
    ByRef phThumbnailId As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DwmRegisterThumbnail = ctypes.windll.dwmapi.DwmRegisterThumbnail
DwmRegisterThumbnail.restype = ctypes.c_int
DwmRegisterThumbnail.argtypes = [
    wintypes.HANDLE,  # hwndDestination : HWND
    wintypes.HANDLE,  # hwndSource : HWND
    ctypes.POINTER(ctypes.c_ssize_t),  # phThumbnailId : INT_PTR* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dwmapi.dll')
DwmRegisterThumbnail = Fiddle::Function.new(
  lib['DwmRegisterThumbnail'],
  [
    Fiddle::TYPE_VOIDP,  # hwndDestination : HWND
    Fiddle::TYPE_VOIDP,  # hwndSource : HWND
    Fiddle::TYPE_VOIDP,  # phThumbnailId : INT_PTR* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "dwmapi")]
extern "system" {
    fn DwmRegisterThumbnail(
        hwndDestination: *mut core::ffi::c_void,  // HWND
        hwndSource: *mut core::ffi::c_void,  // HWND
        phThumbnailId: *mut isize  // INT_PTR* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("dwmapi.dll")]
public static extern int DwmRegisterThumbnail(IntPtr hwndDestination, IntPtr hwndSource, out IntPtr phThumbnailId);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dwmapi_DwmRegisterThumbnail' -Namespace Win32 -PassThru
# $api::DwmRegisterThumbnail(hwndDestination, hwndSource, phThumbnailId)
#uselib "dwmapi.dll"
#func global DwmRegisterThumbnail "DwmRegisterThumbnail" sptr, sptr, sptr
; DwmRegisterThumbnail hwndDestination, hwndSource, varptr(phThumbnailId)   ; 戻り値は stat
; hwndDestination : HWND -> "sptr"
; hwndSource : HWND -> "sptr"
; phThumbnailId : INT_PTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "dwmapi.dll"
#cfunc global DwmRegisterThumbnail "DwmRegisterThumbnail" sptr, sptr, var
; res = DwmRegisterThumbnail(hwndDestination, hwndSource, phThumbnailId)
; hwndDestination : HWND -> "sptr"
; hwndSource : HWND -> "sptr"
; phThumbnailId : INT_PTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT DwmRegisterThumbnail(HWND hwndDestination, HWND hwndSource, INT_PTR* phThumbnailId)
#uselib "dwmapi.dll"
#cfunc global DwmRegisterThumbnail "DwmRegisterThumbnail" intptr, intptr, var
; res = DwmRegisterThumbnail(hwndDestination, hwndSource, phThumbnailId)
; hwndDestination : HWND -> "intptr"
; hwndSource : HWND -> "intptr"
; phThumbnailId : INT_PTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dwmapi = windows.NewLazySystemDLL("dwmapi.dll")
	procDwmRegisterThumbnail = dwmapi.NewProc("DwmRegisterThumbnail")
)

// hwndDestination (HWND), hwndSource (HWND), phThumbnailId (INT_PTR* out)
r1, _, err := procDwmRegisterThumbnail.Call(
	uintptr(hwndDestination),
	uintptr(hwndSource),
	uintptr(phThumbnailId),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function DwmRegisterThumbnail(
  hwndDestination: THandle;   // HWND
  hwndSource: THandle;   // HWND
  phThumbnailId: Pointer   // INT_PTR* out
): Integer; stdcall;
  external 'dwmapi.dll' name 'DwmRegisterThumbnail';
result := DllCall("dwmapi\DwmRegisterThumbnail"
    , "Ptr", hwndDestination   ; HWND
    , "Ptr", hwndSource   ; HWND
    , "Ptr", phThumbnailId   ; INT_PTR* out
    , "Int")   ; return: HRESULT
●DwmRegisterThumbnail(hwndDestination, hwndSource, phThumbnailId) = DLL("dwmapi.dll", "int DwmRegisterThumbnail(void*, void*, void*)")
# 呼び出し: DwmRegisterThumbnail(hwndDestination, hwndSource, phThumbnailId)
# hwndDestination : HWND -> "void*"
# hwndSource : HWND -> "void*"
# phThumbnailId : INT_PTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef DwmRegisterThumbnailNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
typedef DwmRegisterThumbnailDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
final DwmRegisterThumbnail = DynamicLibrary.open('dwmapi.dll')
    .lookupFunction<DwmRegisterThumbnailNative, DwmRegisterThumbnailDart>('DwmRegisterThumbnail');
// hwndDestination : HWND -> Pointer<Void>
// hwndSource : HWND -> Pointer<Void>
// phThumbnailId : INT_PTR* out -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DwmRegisterThumbnail(
  hwndDestination: THandle;   // HWND
  hwndSource: THandle;   // HWND
  phThumbnailId: Pointer   // INT_PTR* out
): Integer; stdcall;
  external 'dwmapi.dll' name 'DwmRegisterThumbnail';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DwmRegisterThumbnail"
  c_DwmRegisterThumbnail :: Ptr () -> Ptr () -> Ptr CIntPtr -> IO Int32
-- hwndDestination : HWND -> Ptr ()
-- hwndSource : HWND -> Ptr ()
-- phThumbnailId : INT_PTR* out -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dwmregisterthumbnail =
  foreign "DwmRegisterThumbnail"
    ((ptr void) @-> (ptr void) @-> (ptr intptr_t) @-> returning int32_t)
(* hwndDestination : HWND -> (ptr void) *)
(* hwndSource : HWND -> (ptr void) *)
(* phThumbnailId : INT_PTR* out -> (ptr intptr_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dwmapi (t "dwmapi.dll"))
(cffi:use-foreign-library dwmapi)

(cffi:defcfun ("DwmRegisterThumbnail" dwm-register-thumbnail :convention :stdcall) :int32
  (hwnd-destination :pointer)   ; HWND
  (hwnd-source :pointer)   ; HWND
  (ph-thumbnail-id :pointer))   ; INT_PTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DwmRegisterThumbnail = Win32::API::More->new('dwmapi',
    'int DwmRegisterThumbnail(HANDLE hwndDestination, HANDLE hwndSource, LPVOID phThumbnailId)');
# my $ret = $DwmRegisterThumbnail->Call($hwndDestination, $hwndSource, $phThumbnailId);
# hwndDestination : HWND -> HANDLE
# hwndSource : HWND -> HANDLE
# phThumbnailId : INT_PTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。