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

DeferWindowPos

関数
一括更新用にウィンドウの位置情報を追加する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

HDWP DeferWindowPos(
    HDWP hWinPosInfo,
    HWND hWnd,
    HWND hWndInsertAfter,   // optional
    INT x,
    INT y,
    INT cx,
    INT cy,
    SET_WINDOW_POS_FLAGS uFlags
);

パラメーター

名前方向説明
hWinPosInfoHDWPin1 つ以上のウィンドウのサイズおよび位置情報を保持する複数ウィンドウ位置構造体へのハンドルです。この構造体は BeginDeferWindowPos または直近の DeferWindowPos 呼び出しによって返されます。
hWndHWNDin更新情報が構造体に格納されるウィンドウへのハンドルです。複数ウィンドウ位置構造体に含まれるすべてのウィンドウは、同じ親を持つ必要があります。
hWndInsertAfterHWNDinoptional

Z オーダーにおいて配置対象ウィンドウの直前に位置するウィンドウへのハンドルです。このパラメーターには、ウィンドウハンドルまたは次のいずれかの値を指定する必要があります。uFlags パラメーターに SWP_NOZORDER フラグが設定されている場合、このパラメーターは無視されます。

意味
HWND_BOTTOM
((HWND)1)
ウィンドウを Z オーダーの最下部に配置します。hWnd パラメーターが最前面ウィンドウを指定している場合、そのウィンドウは最前面の状態を失い、他のすべてのウィンドウの最下部に配置されます。
HWND_NOTOPMOST
((HWND)-2)
ウィンドウを、すべての非最前面ウィンドウの上(つまりすべての最前面ウィンドウの後ろ)に配置します。ウィンドウがすでに非最前面ウィンドウである場合、このフラグは効果がありません。
HWND_TOP
((HWND)0)
ウィンドウを Z オーダーの最上部に配置します。
HWND_TOPMOST
((HWND)-1)
ウィンドウを、すべての非最前面ウィンドウの上に配置します。このウィンドウは、非アクティブ化されても最前面の位置を維持します。
xINTinウィンドウの左上隅の x 座標です。
yINTinウィンドウの左上隅の y 座標です。
cxINTinウィンドウの新しい幅(ピクセル単位)です。
cyINTinウィンドウの新しい高さ(ピクセル単位)です。
uFlagsSET_WINDOW_POS_FLAGSin

ウィンドウのサイズと位置に影響を与える、次の値の組み合わせです。

意味
SWP_DRAWFRAME
0x0020
ウィンドウの周囲に(ウィンドウのクラス定義で指定された)フレームを描画します。
SWP_FRAMECHANGED
0x0020
ウィンドウのサイズが変更されない場合でも、ウィンドウに WM_NCCALCSIZE メッセージを送信します。このフラグを指定しない場合、WM_NCCALCSIZE はウィンドウのサイズが変更されるときにのみ送信されます。
SWP_HIDEWINDOW
0x0080
ウィンドウを非表示にします。
SWP_NOACTIVATE
0x0010
ウィンドウをアクティブ化しません。このフラグを設定しない場合、ウィンドウはアクティブ化され、(hWndInsertAfter パラメーターの設定に応じて)最前面グループまたは非最前面グループのいずれかの最上部に移動します。
SWP_NOCOPYBITS
0x0100
クライアント領域の内容全体を破棄します。このフラグを指定しない場合、クライアント領域の有効な内容が保存され、ウィンドウのサイズ変更または再配置後にクライアント領域へ復元されます。
SWP_NOMOVE
0x0002
現在の位置を維持します(x および y パラメーターを無視します)。
SWP_NOOWNERZORDER
0x0200
オーナーウィンドウの Z オーダー上の位置を変更しません。
SWP_NOREDRAW
0x0008
変更を再描画しません。このフラグを設定すると、いかなる種類の再描画も行われません。これはクライアント領域、非クライアント領域(タイトルバーやスクロールバーを含む)、およびウィンドウの移動によって露出した親ウィンドウの部分に適用されます。このフラグを設定した場合、アプリケーションは再描画が必要なウィンドウおよび親ウィンドウの部分を明示的に無効化または再描画する必要があります。
SWP_NOREPOSITION
0x0200
SWP_NOOWNERZORDER フラグと同じです。
SWP_NOSENDCHANGING
0x0400
ウィンドウが WM_WINDOWPOSCHANGING メッセージを受信しないようにします。
SWP_NOSIZE
0x0001
現在のサイズを維持します(cx および cy パラメーターを無視します)。
SWP_NOZORDER
0x0004
現在の Z オーダーを維持します(hWndInsertAfter パラメーターを無視します)。
SWP_SHOWWINDOW
0x0040
ウィンドウを表示します。

戻り値の型: HDWP

公式ドキュメント

指定したウィンドウについて、指定した複数ウィンドウ位置構造体を更新します。

戻り値

型: HDWP

戻り値は、更新された複数ウィンドウ位置構造体を識別します。この関数が返すハンドルは、関数に渡したハンドルと異なる場合があります。この関数が返す新しいハンドルは、次回の DeferWindowPos または EndDeferWindowPos 関数の呼び出し時に渡す必要があります。

関数の成功に十分なシステムリソースがない場合、戻り値は NULL になります。拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

DeferWindowPos の呼び出しが失敗した場合、アプリケーションはウィンドウ位置設定操作を中止し、EndDeferWindowPos を呼び出さないでください。

SWP_NOZORDER が指定されていない場合、システムは hWnd パラメーターで識別されるウィンドウを、hWndInsertAfter パラメーターで識別されるウィンドウの直後の位置に配置します。hWndInsertAfterNULL または HWND_TOP の場合、システムは hWnd ウィンドウを Z オーダーの最上部に配置します。hWndInsertAfterHWND_BOTTOM に設定されている場合、システムは hWnd ウィンドウを Z オーダーの最下部に配置します。

子ウィンドウのすべての座標は、親ウィンドウのクライアント領域の左上隅を基準とした相対座標です。

ウィンドウを最前面ウィンドウにするには、hWndInsertAfterHWND_TOPMOST フラグに設定して SWP_NOZORDER フラグが設定されていないことを確認するか、または既存の最前面ウィンドウより上になるように Z オーダー上の位置を設定します。非最前面ウィンドウが最前面にされると、その所有ウィンドウも最前面になります。ただし、そのオーナーは変更されません。

SWP_NOACTIVATE フラグと SWP_NOZORDER フラグのいずれも指定されていない場合(つまり、アプリケーションがウィンドウのアクティブ化と Z オーダー上の位置変更を同時に要求する場合)、hWndInsertAfter に指定された値は、次の状況においてのみ使用されます。

アプリケーションは、非アクティブなウィンドウをアクティブ化する際に、同時にそれを Z オーダーの最上部に移動させずにアクティブ化することはできません。アプリケーションは、アクティブ化されたウィンドウの Z オーダー上の位置を制限なく変更できます。また、ウィンドウをアクティブ化してから、最前面ウィンドウまたは非最前面ウィンドウの最上部に移動させることもできます。

最前面ウィンドウは、Z オーダーの最下部(HWND_BOTTOM)または非最前面ウィンドウの後ろに再配置されると、最前面ではなくなります。最前面ウィンドウが非最前面にされると、そのオーナーおよび所有ウィンドウも非最前面ウィンドウになります。

非最前面ウィンドウは最前面ウィンドウを所有できますが、その逆はできません。最前面ウィンドウが所有するウィンドウ(たとえばダイアログボックス)は、それ自体が最前面ウィンドウになり、すべての所有ウィンドウがそのオーナーより上に維持されるようにします。

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

各言語での呼び出し定義

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

HDWP DeferWindowPos(
    HDWP hWinPosInfo,
    HWND hWnd,
    HWND hWndInsertAfter,   // optional
    INT x,
    INT y,
    INT cx,
    INT cy,
    SET_WINDOW_POS_FLAGS uFlags
);
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr DeferWindowPos(
    IntPtr hWinPosInfo,   // HDWP
    IntPtr hWnd,   // HWND
    IntPtr hWndInsertAfter,   // HWND optional
    int x,   // INT
    int y,   // INT
    int cx,   // INT
    int cy,   // INT
    uint uFlags   // SET_WINDOW_POS_FLAGS
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DeferWindowPos(
    hWinPosInfo As IntPtr,   ' HDWP
    hWnd As IntPtr,   ' HWND
    hWndInsertAfter As IntPtr,   ' HWND optional
    x As Integer,   ' INT
    y As Integer,   ' INT
    cx As Integer,   ' INT
    cy As Integer,   ' INT
    uFlags As UInteger   ' SET_WINDOW_POS_FLAGS
) As IntPtr
End Function
' hWinPosInfo : HDWP
' hWnd : HWND
' hWndInsertAfter : HWND optional
' x : INT
' y : INT
' cx : INT
' cy : INT
' uFlags : SET_WINDOW_POS_FLAGS
Declare PtrSafe Function DeferWindowPos Lib "user32" ( _
    ByVal hWinPosInfo As LongPtr, _
    ByVal hWnd As LongPtr, _
    ByVal hWndInsertAfter As LongPtr, _
    ByVal x As Long, _
    ByVal y As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal uFlags As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DeferWindowPos = ctypes.windll.user32.DeferWindowPos
DeferWindowPos.restype = ctypes.c_void_p
DeferWindowPos.argtypes = [
    wintypes.HANDLE,  # hWinPosInfo : HDWP
    wintypes.HANDLE,  # hWnd : HWND
    wintypes.HANDLE,  # hWndInsertAfter : HWND optional
    ctypes.c_int,  # x : INT
    ctypes.c_int,  # y : INT
    ctypes.c_int,  # cx : INT
    ctypes.c_int,  # cy : INT
    wintypes.DWORD,  # uFlags : SET_WINDOW_POS_FLAGS
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
DeferWindowPos = Fiddle::Function.new(
  lib['DeferWindowPos'],
  [
    Fiddle::TYPE_VOIDP,  # hWinPosInfo : HDWP
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    Fiddle::TYPE_VOIDP,  # hWndInsertAfter : HWND optional
    Fiddle::TYPE_INT,  # x : INT
    Fiddle::TYPE_INT,  # y : INT
    Fiddle::TYPE_INT,  # cx : INT
    Fiddle::TYPE_INT,  # cy : INT
    -Fiddle::TYPE_INT,  # uFlags : SET_WINDOW_POS_FLAGS
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "user32")]
extern "system" {
    fn DeferWindowPos(
        hWinPosInfo: *mut core::ffi::c_void,  // HDWP
        hWnd: *mut core::ffi::c_void,  // HWND
        hWndInsertAfter: *mut core::ffi::c_void,  // HWND optional
        x: i32,  // INT
        y: i32,  // INT
        cx: i32,  // INT
        cy: i32,  // INT
        uFlags: u32  // SET_WINDOW_POS_FLAGS
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", SetLastError = true)]
public static extern IntPtr DeferWindowPos(IntPtr hWinPosInfo, IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DeferWindowPos' -Namespace Win32 -PassThru
# $api::DeferWindowPos(hWinPosInfo, hWnd, hWndInsertAfter, x, y, cx, cy, uFlags)
#uselib "USER32.dll"
#func global DeferWindowPos "DeferWindowPos" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DeferWindowPos hWinPosInfo, hWnd, hWndInsertAfter, x, y, cx, cy, uFlags   ; 戻り値は stat
; hWinPosInfo : HDWP -> "sptr"
; hWnd : HWND -> "sptr"
; hWndInsertAfter : HWND optional -> "sptr"
; x : INT -> "sptr"
; y : INT -> "sptr"
; cx : INT -> "sptr"
; cy : INT -> "sptr"
; uFlags : SET_WINDOW_POS_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global DeferWindowPos "DeferWindowPos" sptr, sptr, sptr, int, int, int, int, int
; res = DeferWindowPos(hWinPosInfo, hWnd, hWndInsertAfter, x, y, cx, cy, uFlags)
; hWinPosInfo : HDWP -> "sptr"
; hWnd : HWND -> "sptr"
; hWndInsertAfter : HWND optional -> "sptr"
; x : INT -> "int"
; y : INT -> "int"
; cx : INT -> "int"
; cy : INT -> "int"
; uFlags : SET_WINDOW_POS_FLAGS -> "int"
; HDWP DeferWindowPos(HDWP hWinPosInfo, HWND hWnd, HWND hWndInsertAfter, INT x, INT y, INT cx, INT cy, SET_WINDOW_POS_FLAGS uFlags)
#uselib "USER32.dll"
#cfunc global DeferWindowPos "DeferWindowPos" intptr, intptr, intptr, int, int, int, int, int
; res = DeferWindowPos(hWinPosInfo, hWnd, hWndInsertAfter, x, y, cx, cy, uFlags)
; hWinPosInfo : HDWP -> "intptr"
; hWnd : HWND -> "intptr"
; hWndInsertAfter : HWND optional -> "intptr"
; x : INT -> "int"
; y : INT -> "int"
; cx : INT -> "int"
; cy : INT -> "int"
; uFlags : SET_WINDOW_POS_FLAGS -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procDeferWindowPos = user32.NewProc("DeferWindowPos")
)

// hWinPosInfo (HDWP), hWnd (HWND), hWndInsertAfter (HWND optional), x (INT), y (INT), cx (INT), cy (INT), uFlags (SET_WINDOW_POS_FLAGS)
r1, _, err := procDeferWindowPos.Call(
	uintptr(hWinPosInfo),
	uintptr(hWnd),
	uintptr(hWndInsertAfter),
	uintptr(x),
	uintptr(y),
	uintptr(cx),
	uintptr(cy),
	uintptr(uFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HDWP
function DeferWindowPos(
  hWinPosInfo: THandle;   // HDWP
  hWnd: THandle;   // HWND
  hWndInsertAfter: THandle;   // HWND optional
  x: Integer;   // INT
  y: Integer;   // INT
  cx: Integer;   // INT
  cy: Integer;   // INT
  uFlags: DWORD   // SET_WINDOW_POS_FLAGS
): THandle; stdcall;
  external 'USER32.dll' name 'DeferWindowPos';
result := DllCall("USER32\DeferWindowPos"
    , "Ptr", hWinPosInfo   ; HDWP
    , "Ptr", hWnd   ; HWND
    , "Ptr", hWndInsertAfter   ; HWND optional
    , "Int", x   ; INT
    , "Int", y   ; INT
    , "Int", cx   ; INT
    , "Int", cy   ; INT
    , "UInt", uFlags   ; SET_WINDOW_POS_FLAGS
    , "Ptr")   ; return: HDWP
●DeferWindowPos(hWinPosInfo, hWnd, hWndInsertAfter, x, y, cx, cy, uFlags) = DLL("USER32.dll", "void* DeferWindowPos(void*, void*, void*, int, int, int, int, dword)")
# 呼び出し: DeferWindowPos(hWinPosInfo, hWnd, hWndInsertAfter, x, y, cx, cy, uFlags)
# hWinPosInfo : HDWP -> "void*"
# hWnd : HWND -> "void*"
# hWndInsertAfter : HWND optional -> "void*"
# x : INT -> "int"
# y : INT -> "int"
# cx : INT -> "int"
# cy : INT -> "int"
# uFlags : SET_WINDOW_POS_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef DeferWindowPosNative = Pointer<Void> Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Int32, Int32, Int32, Int32, Uint32);
typedef DeferWindowPosDart = Pointer<Void> Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, int, int, int, int);
final DeferWindowPos = DynamicLibrary.open('USER32.dll')
    .lookupFunction<DeferWindowPosNative, DeferWindowPosDart>('DeferWindowPos');
// hWinPosInfo : HDWP -> Pointer<Void>
// hWnd : HWND -> Pointer<Void>
// hWndInsertAfter : HWND optional -> Pointer<Void>
// x : INT -> Int32
// y : INT -> Int32
// cx : INT -> Int32
// cy : INT -> Int32
// uFlags : SET_WINDOW_POS_FLAGS -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DeferWindowPos(
  hWinPosInfo: THandle;   // HDWP
  hWnd: THandle;   // HWND
  hWndInsertAfter: THandle;   // HWND optional
  x: Integer;   // INT
  y: Integer;   // INT
  cx: Integer;   // INT
  cy: Integer;   // INT
  uFlags: DWORD   // SET_WINDOW_POS_FLAGS
): THandle; stdcall;
  external 'USER32.dll' name 'DeferWindowPos';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DeferWindowPos"
  c_DeferWindowPos :: Ptr () -> Ptr () -> Ptr () -> Int32 -> Int32 -> Int32 -> Int32 -> Word32 -> IO (Ptr ())
-- hWinPosInfo : HDWP -> Ptr ()
-- hWnd : HWND -> Ptr ()
-- hWndInsertAfter : HWND optional -> Ptr ()
-- x : INT -> Int32
-- y : INT -> Int32
-- cx : INT -> Int32
-- cy : INT -> Int32
-- uFlags : SET_WINDOW_POS_FLAGS -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let deferwindowpos =
  foreign "DeferWindowPos"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> uint32_t @-> returning (ptr void))
(* hWinPosInfo : HDWP -> (ptr void) *)
(* hWnd : HWND -> (ptr void) *)
(* hWndInsertAfter : HWND optional -> (ptr void) *)
(* x : INT -> int32_t *)
(* y : INT -> int32_t *)
(* cx : INT -> int32_t *)
(* cy : INT -> int32_t *)
(* uFlags : SET_WINDOW_POS_FLAGS -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)

(cffi:defcfun ("DeferWindowPos" defer-window-pos :convention :stdcall) :pointer
  (h-win-pos-info :pointer)   ; HDWP
  (h-wnd :pointer)   ; HWND
  (h-wnd-insert-after :pointer)   ; HWND optional
  (x :int32)   ; INT
  (y :int32)   ; INT
  (cx :int32)   ; INT
  (cy :int32)   ; INT
  (u-flags :uint32))   ; SET_WINDOW_POS_FLAGS
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DeferWindowPos = Win32::API::More->new('USER32',
    'HANDLE DeferWindowPos(HANDLE hWinPosInfo, HANDLE hWnd, HANDLE hWndInsertAfter, int x, int y, int cx, int cy, DWORD uFlags)');
# my $ret = $DeferWindowPos->Call($hWinPosInfo, $hWnd, $hWndInsertAfter, $x, $y, $cx, $cy, $uFlags);
# hWinPosInfo : HDWP -> HANDLE
# hWnd : HWND -> HANDLE
# hWndInsertAfter : HWND optional -> HANDLE
# x : INT -> int
# y : INT -> int
# cx : INT -> int
# cy : INT -> int
# uFlags : SET_WINDOW_POS_FLAGS -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型