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

SetWindowPos

関数
ウィンドウの位置やサイズやZ順序を変更する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetWindowPos(
    HWND hWnd,
    HWND hWndInsertAfter,   // optional
    INT X,
    INT Y,
    INT cx,
    INT cy,
    SET_WINDOW_POS_FLAGS uFlags
);

パラメーター

名前方向説明
hWndHWNDinウィンドウへのハンドルです。
hWndInsertAfterHWNDinoptional

Z オーダーにおいて、配置するウィンドウの直前に位置するウィンドウへのハンドルです。このパラメーターには、ウィンドウハンドルか、次のいずれかの値を指定する必要があります。

意味
HWND_BOTTOM
(HWND)1
ウィンドウを Z オーダーの最下部に配置します。hWnd パラメーターが最前面ウィンドウを指している場合、そのウィンドウは最前面の状態を失い、他のすべてのウィンドウの最下部に配置されます。
HWND_NOTOPMOST
(HWND)-2
ウィンドウをすべての非最前面ウィンドウの上(つまり、すべての最前面ウィンドウの後ろ)に配置します。ウィンドウが既に非最前面ウィンドウである場合、このフラグは効果がありません。
HWND_TOP
(HWND)0
ウィンドウを Z オーダーの最上部に配置します。
HWND_TOPMOST
(HWND)-1
ウィンドウをすべての非最前面ウィンドウの上に配置します。このウィンドウは、非アクティブになっても最前面の位置を維持します。

このパラメーターの使用方法の詳細については、後述の「解説」セクションを参照してください。

XINTinウィンドウの左端の新しい位置です(クライアント座標)。
YINTinウィンドウの上端の新しい位置です(クライアント座標)。
cxINTinウィンドウの新しい幅です(ピクセル単位)。
cyINTinウィンドウの新しい高さです(ピクセル単位)。
uFlagsSET_WINDOW_POS_FLAGSin

ウィンドウのサイズ変更と位置指定に関するフラグです。このパラメーターには、次の値の組み合わせを指定できます。

意味
SWP_ASYNCWINDOWPOS
0x4000
呼び出し元スレッドとウィンドウを所有するスレッドが異なる入力キューにアタッチされている場合、システムはその要求をウィンドウを所有するスレッドにポストします。これにより、他のスレッドが要求を処理している間、呼び出し元スレッドの実行がブロックされるのを防ぎます。
SWP_DEFERERASE
0x2000
WM_SYNCPAINT メッセージの生成を抑止します。
SWP_DRAWFRAME
0x0020
ウィンドウの周囲にフレーム(ウィンドウのクラス記述で定義されたもの)を描画します。
SWP_FRAMECHANGED
0x0020
SetWindowLong 関数で設定された新しいフレームスタイルを適用します。ウィンドウのサイズが変更されない場合でも、ウィンドウに 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
ウィンドウを表示します。

戻り値の型: BOOL

公式ドキュメント

子ウィンドウ、ポップアップウィンドウ、またはトップレベルウィンドウのサイズ、位置、および Z オーダーを変更します。これらのウィンドウは画面上での表示順序に従って並びます。最前面のウィンドウが最も高い順位を持ち、Z オーダーの先頭に位置します。

戻り値

型: BOOL

関数が成功すると、戻り値は 0 以外になります。

関数が失敗すると、戻り値は 0 になります。拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

Vista の再設計の一環として、すべてのサービスは対話型デスクトップから Session 0 へ移されました。hwnd およびウィンドウマネージャーの操作はセッション内でのみ有効であり、セッションをまたいで hwnd を操作しようとすると失敗します。詳細については、The Windows Vista Developer Story: Application Compatibility Cookbook を参照してください。

SetWindowLong を使用して特定のウィンドウデータを変更した場合、その変更を有効にするには SetWindowPos を呼び出す必要があります。uFlags には次の組み合わせを使用します: SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED

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

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

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

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

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

アプリケーションがフォアグラウンドにないにもかかわらずフォアグラウンドにあるべき場合は、SetForegroundWindow 関数を呼び出す必要があります。

SetWindowPos を使用してウィンドウを最上部に表示するには、そのウィンドウを所有するプロセスが SetForegroundWindow の権限を持っている必要があります。

例については、Initializing a Dialog Box を参照してください。

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

各言語での呼び出し定義

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

BOOL SetWindowPos(
    HWND hWnd,
    HWND hWndInsertAfter,   // optional
    INT X,
    INT Y,
    INT cx,
    INT cy,
    SET_WINDOW_POS_FLAGS uFlags
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetWindowPos(
    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 SetWindowPos(
    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 <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hWnd : HWND
' hWndInsertAfter : HWND optional
' X : INT
' Y : INT
' cx : INT
' cy : INT
' uFlags : SET_WINDOW_POS_FLAGS
Declare PtrSafe Function SetWindowPos Lib "user32" ( _
    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 Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetWindowPos = ctypes.windll.user32.SetWindowPos
SetWindowPos.restype = wintypes.BOOL
SetWindowPos.argtypes = [
    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')
SetWindowPos = Fiddle::Function.new(
  lib['SetWindowPos'],
  [
    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_INT)
#[link(name = "user32")]
extern "system" {
    fn SetWindowPos(
        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
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetWindowPos' -Namespace Win32 -PassThru
# $api::SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags)
#uselib "USER32.dll"
#func global SetWindowPos "SetWindowPos" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetWindowPos hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags   ; 戻り値は stat
; 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 SetWindowPos "SetWindowPos" sptr, sptr, int, int, int, int, int
; res = SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags)
; 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"
; BOOL SetWindowPos(HWND hWnd, HWND hWndInsertAfter, INT X, INT Y, INT cx, INT cy, SET_WINDOW_POS_FLAGS uFlags)
#uselib "USER32.dll"
#cfunc global SetWindowPos "SetWindowPos" intptr, intptr, int, int, int, int, int
; res = SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags)
; 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")
	procSetWindowPos = user32.NewProc("SetWindowPos")
)

// hWnd (HWND), hWndInsertAfter (HWND optional), X (INT), Y (INT), cx (INT), cy (INT), uFlags (SET_WINDOW_POS_FLAGS)
r1, _, err := procSetWindowPos.Call(
	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   // BOOL
function SetWindowPos(
  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
): BOOL; stdcall;
  external 'USER32.dll' name 'SetWindowPos';
result := DllCall("USER32\SetWindowPos"
    , "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
    , "Int")   ; return: BOOL
●SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags) = DLL("USER32.dll", "bool SetWindowPos(void*, void*, int, int, int, int, dword)")
# 呼び出し: SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags)
# 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 SetWindowPos(
    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) i32;
proc SetWindowPos(
    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
): int32 {.importc: "SetWindowPos", stdcall, dynlib: "USER32.dll".}
pragma(lib, "user32");
extern(Windows)
int SetWindowPos(
    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((:SetWindowPos, "USER32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}, Int32, Int32, Int32, Int32, UInt32),
      hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags)
# 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[[
int32_t SetWindowPos(
    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.SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags)
-- 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 SetWindowPos = lib.func('__stdcall', 'SetWindowPos', 'int32_t', ['void *', 'void *', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'uint32_t']);
// SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags)
// 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", {
  SetWindowPos: { parameters: ["pointer", "pointer", "i32", "i32", "i32", "i32", "u32"], result: "i32" },
});
// lib.symbols.SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags)
// 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
int32_t SetWindowPos(
    void* hWnd,
    void* hWndInsertAfter,
    int32_t X,
    int32_t Y,
    int32_t cx,
    int32_t cy,
    uint32_t uFlags);
C, "USER32.dll");
// $ffi->SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
// 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);
    boolean SetWindowPos(
        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 SetWindowPos = SetWindowPos(
    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
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetWindowPosNative = Int32 Function(Pointer<Void>, Pointer<Void>, Int32, Int32, Int32, Int32, Uint32);
typedef SetWindowPosDart = int Function(Pointer<Void>, Pointer<Void>, int, int, int, int, int);
final SetWindowPos = DynamicLibrary.open('USER32.dll')
    .lookupFunction<SetWindowPosNative, SetWindowPosDart>('SetWindowPos');
// 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 SetWindowPos(
  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
): BOOL; stdcall;
  external 'USER32.dll' name 'SetWindowPos';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetWindowPos"
  c_SetWindowPos :: Ptr () -> Ptr () -> Int32 -> Int32 -> Int32 -> Int32 -> Word32 -> IO CInt
-- 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 setwindowpos =
  foreign "SetWindowPos"
    ((ptr void) @-> (ptr void) @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> uint32_t @-> returning int32_t)
(* 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 ("SetWindowPos" set-window-pos :convention :stdcall) :int32
  (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 $SetWindowPos = Win32::API::More->new('USER32',
    'BOOL SetWindowPos(HANDLE hWnd, HANDLE hWndInsertAfter, int X, int Y, int cx, int cy, DWORD uFlags)');
# my $ret = $SetWindowPos->Call($hWnd, $hWndInsertAfter, $X, $Y, $cx, $cy, $uFlags);
# 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 を使用。

関連項目

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