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

AdjustWindowRect

関数
クライアント領域から必要なウィンドウ矩形を算出する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL AdjustWindowRect(
    RECT* lpRect,
    WINDOW_STYLE dwStyle,
    BOOL bMenu
);

パラメーター

名前方向
lpRectRECT*inout
dwStyleWINDOW_STYLEin
bMenuBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procAdjustWindowRect = user32.NewProc("AdjustWindowRect")
)

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