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

AdjustWindowRectEx

関数
拡張スタイルを考慮しウィンドウ矩形を算出する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL AdjustWindowRectEx(
    RECT* lpRect,
    WINDOW_STYLE dwStyle,
    BOOL bMenu,
    WINDOW_EX_STYLE dwExStyle
);

パラメーター

名前方向
lpRectRECT*inout
dwStyleWINDOW_STYLEin
bMenuBOOLin
dwExStyleWINDOW_EX_STYLEin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL AdjustWindowRectEx(
    RECT* lpRect,
    WINDOW_STYLE dwStyle,
    BOOL bMenu,
    WINDOW_EX_STYLE dwExStyle
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool AdjustWindowRectEx(
    IntPtr lpRect,   // RECT* in/out
    uint dwStyle,   // WINDOW_STYLE
    bool bMenu,   // BOOL
    uint dwExStyle   // WINDOW_EX_STYLE
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function AdjustWindowRectEx(
    lpRect As IntPtr,   ' RECT* in/out
    dwStyle As UInteger,   ' WINDOW_STYLE
    bMenu As Boolean,   ' BOOL
    dwExStyle As UInteger   ' WINDOW_EX_STYLE
) As Boolean
End Function
' lpRect : RECT* in/out
' dwStyle : WINDOW_STYLE
' bMenu : BOOL
' dwExStyle : WINDOW_EX_STYLE
Declare PtrSafe Function AdjustWindowRectEx Lib "user32" ( _
    ByVal lpRect As LongPtr, _
    ByVal dwStyle As Long, _
    ByVal bMenu As Long, _
    ByVal dwExStyle As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

AdjustWindowRectEx = ctypes.windll.user32.AdjustWindowRectEx
AdjustWindowRectEx.restype = wintypes.BOOL
AdjustWindowRectEx.argtypes = [
    ctypes.c_void_p,  # lpRect : RECT* in/out
    wintypes.DWORD,  # dwStyle : WINDOW_STYLE
    wintypes.BOOL,  # bMenu : BOOL
    wintypes.DWORD,  # dwExStyle : WINDOW_EX_STYLE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
AdjustWindowRectEx = Fiddle::Function.new(
  lib['AdjustWindowRectEx'],
  [
    Fiddle::TYPE_VOIDP,  # lpRect : RECT* in/out
    -Fiddle::TYPE_INT,  # dwStyle : WINDOW_STYLE
    Fiddle::TYPE_INT,  # bMenu : BOOL
    -Fiddle::TYPE_INT,  # dwExStyle : WINDOW_EX_STYLE
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn AdjustWindowRectEx(
        lpRect: *mut RECT,  // RECT* in/out
        dwStyle: u32,  // WINDOW_STYLE
        bMenu: i32,  // BOOL
        dwExStyle: u32  // WINDOW_EX_STYLE
    ) -> 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 AdjustWindowRectEx(IntPtr lpRect, uint dwStyle, bool bMenu, uint dwExStyle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_AdjustWindowRectEx' -Namespace Win32 -PassThru
# $api::AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle)
#uselib "USER32.dll"
#func global AdjustWindowRectEx "AdjustWindowRectEx" sptr, sptr, sptr, sptr
; AdjustWindowRectEx varptr(lpRect), dwStyle, bMenu, dwExStyle   ; 戻り値は stat
; lpRect : RECT* in/out -> "sptr"
; dwStyle : WINDOW_STYLE -> "sptr"
; bMenu : BOOL -> "sptr"
; dwExStyle : WINDOW_EX_STYLE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global AdjustWindowRectEx "AdjustWindowRectEx" var, int, int, int
; res = AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle)
; lpRect : RECT* in/out -> "var"
; dwStyle : WINDOW_STYLE -> "int"
; bMenu : BOOL -> "int"
; dwExStyle : WINDOW_EX_STYLE -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL AdjustWindowRectEx(RECT* lpRect, WINDOW_STYLE dwStyle, BOOL bMenu, WINDOW_EX_STYLE dwExStyle)
#uselib "USER32.dll"
#cfunc global AdjustWindowRectEx "AdjustWindowRectEx" var, int, int, int
; res = AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle)
; lpRect : RECT* in/out -> "var"
; dwStyle : WINDOW_STYLE -> "int"
; bMenu : BOOL -> "int"
; dwExStyle : WINDOW_EX_STYLE -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procAdjustWindowRectEx = user32.NewProc("AdjustWindowRectEx")
)

// lpRect (RECT* in/out), dwStyle (WINDOW_STYLE), bMenu (BOOL), dwExStyle (WINDOW_EX_STYLE)
r1, _, err := procAdjustWindowRectEx.Call(
	uintptr(lpRect),
	uintptr(dwStyle),
	uintptr(bMenu),
	uintptr(dwExStyle),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function AdjustWindowRectEx(
  lpRect: Pointer;   // RECT* in/out
  dwStyle: DWORD;   // WINDOW_STYLE
  bMenu: BOOL;   // BOOL
  dwExStyle: DWORD   // WINDOW_EX_STYLE
): BOOL; stdcall;
  external 'USER32.dll' name 'AdjustWindowRectEx';
result := DllCall("USER32\AdjustWindowRectEx"
    , "Ptr", lpRect   ; RECT* in/out
    , "UInt", dwStyle   ; WINDOW_STYLE
    , "Int", bMenu   ; BOOL
    , "UInt", dwExStyle   ; WINDOW_EX_STYLE
    , "Int")   ; return: BOOL
●AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle) = DLL("USER32.dll", "bool AdjustWindowRectEx(void*, dword, bool, dword)")
# 呼び出し: AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle)
# lpRect : RECT* in/out -> "void*"
# dwStyle : WINDOW_STYLE -> "dword"
# bMenu : BOOL -> "bool"
# dwExStyle : WINDOW_EX_STYLE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。