ホーム › UI.WindowsAndMessaging › AdjustWindowRectEx
AdjustWindowRectEx
関数拡張スタイルを考慮しウィンドウ矩形を算出する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL AdjustWindowRectEx(
RECT* lpRect,
WINDOW_STYLE dwStyle,
BOOL bMenu,
WINDOW_EX_STYLE dwExStyle
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpRect | RECT* | inout | 希望するクライアント領域の左上隅と右下隅の座標を格納する RECT 構造体へのポインターです。関数が戻ると、この構造体には希望するクライアント領域を収めるために必要なウィンドウの左上隅と右下隅の座標が格納されます。 |
| dwStyle | WINDOW_STYLE | in | 必要なサイズを計算する対象のウィンドウのウィンドウ スタイルです。WS_OVERLAPPED スタイルは指定できないことに注意してください。 |
| bMenu | BOOL | in | ウィンドウがメニューを持つかどうかを示します。 |
| dwExStyle | WINDOW_EX_STYLE | in | 必要なサイズを計算する対象のウィンドウの拡張ウィンドウ スタイルです。 |
戻り値の型: BOOL
公式ドキュメント
希望するクライアント矩形のサイズに基づいて、必要なウィンドウ矩形のサイズを計算します。算出されたウィンドウ矩形を CreateWindowEx 関数に渡すことで、クライアント領域が希望のサイズになるウィンドウを作成できます。
戻り値
解説(Remarks)
クライアント矩形とは、クライアント領域を完全に囲む最小の矩形です。ウィンドウ矩形とは、クライアント領域と非クライアント領域を含む、ウィンドウ全体を完全に囲む最小の矩形です。
AdjustWindowRectEx 関数は、メニュー バーが 2 行以上に折り返される場合でも、追加の領域を加算しません。
AdjustWindowRectEx 関数は、WS_VSCROLL スタイルや WS_HSCROLL スタイルを考慮しません。スクロール バーを考慮するには、GetSystemMetrics 関数を SM_CXVSCROLL または SM_CYHSCROLL を指定して呼び出してください。
この API は DPI を認識しないため、呼び出し元のスレッドがモニターごとの DPI を認識する場合は使用しないでください。この API の DPI 対応版については、AdjustWindowsRectExForDPI を参照してください。DPI 認識の詳細については、Windows の高 DPI ドキュメントを参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 <MarshalAs(UnmanagedType.Bool)> 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 方式にも切替可。#uselib "USER32.dll" #cfunc global AdjustWindowRectEx "AdjustWindowRectEx" sptr, int, int, int ; res = AdjustWindowRectEx(varptr(lpRect), dwStyle, bMenu, dwExStyle) ; lpRect : RECT* in/out -> "sptr" ; dwStyle : WINDOW_STYLE -> "int" ; bMenu : BOOL -> "int" ; dwExStyle : WINDOW_EX_STYLE -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; BOOL AdjustWindowRectEx(RECT* lpRect, WINDOW_STYLE dwStyle, BOOL bMenu, WINDOW_EX_STYLE dwExStyle) #uselib "USER32.dll" #cfunc global AdjustWindowRectEx "AdjustWindowRectEx" intptr, int, int, int ; res = AdjustWindowRectEx(varptr(lpRect), dwStyle, bMenu, dwExStyle) ; lpRect : RECT* in/out -> "intptr" ; dwStyle : WINDOW_STYLE -> "int" ; bMenu : BOOL -> "int" ; dwExStyle : WINDOW_EX_STYLE -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。const std = @import("std");
extern "user32" fn AdjustWindowRectEx(
lpRect: [*c]RECT, // RECT* in/out
dwStyle: u32, // WINDOW_STYLE
bMenu: i32, // BOOL
dwExStyle: u32 // WINDOW_EX_STYLE
) callconv(std.os.windows.WINAPI) i32;proc AdjustWindowRectEx(
lpRect: ptr RECT, # RECT* in/out
dwStyle: uint32, # WINDOW_STYLE
bMenu: int32, # BOOL
dwExStyle: uint32 # WINDOW_EX_STYLE
): int32 {.importc: "AdjustWindowRectEx", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int AdjustWindowRectEx(
RECT* lpRect, // RECT* in/out
uint dwStyle, // WINDOW_STYLE
int bMenu, // BOOL
uint dwExStyle // WINDOW_EX_STYLE
);ccall((:AdjustWindowRectEx, "USER32.dll"), stdcall, Int32,
(Ptr{RECT}, UInt32, Int32, UInt32),
lpRect, dwStyle, bMenu, dwExStyle)
# lpRect : RECT* in/out -> Ptr{RECT}
# dwStyle : WINDOW_STYLE -> UInt32
# bMenu : BOOL -> Int32
# dwExStyle : WINDOW_EX_STYLE -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t AdjustWindowRectEx(
void* lpRect,
uint32_t dwStyle,
int32_t bMenu,
uint32_t dwExStyle);
]]
local user32 = ffi.load("user32")
-- user32.AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle)
-- lpRect : RECT* in/out
-- dwStyle : WINDOW_STYLE
-- bMenu : BOOL
-- dwExStyle : WINDOW_EX_STYLE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const AdjustWindowRectEx = lib.func('__stdcall', 'AdjustWindowRectEx', 'int32_t', ['void *', 'uint32_t', 'int32_t', 'uint32_t']);
// AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle)
// lpRect : RECT* in/out -> 'void *'
// dwStyle : WINDOW_STYLE -> 'uint32_t'
// bMenu : BOOL -> 'int32_t'
// dwExStyle : WINDOW_EX_STYLE -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
AdjustWindowRectEx: { parameters: ["pointer", "u32", "i32", "u32"], result: "i32" },
});
// lib.symbols.AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle)
// lpRect : RECT* in/out -> "pointer"
// dwStyle : WINDOW_STYLE -> "u32"
// bMenu : BOOL -> "i32"
// dwExStyle : WINDOW_EX_STYLE -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t AdjustWindowRectEx(
void* lpRect,
uint32_t dwStyle,
int32_t bMenu,
uint32_t dwExStyle);
C, "USER32.dll");
// $ffi->AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle);
// lpRect : RECT* in/out
// dwStyle : WINDOW_STYLE
// bMenu : BOOL
// dwExStyle : WINDOW_EX_STYLE
// 構造体/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 AdjustWindowRectEx(
Pointer lpRect, // RECT* in/out
int dwStyle, // WINDOW_STYLE
boolean bMenu, // BOOL
int dwExStyle // WINDOW_EX_STYLE
);
}@[Link("user32")]
lib LibUSER32
fun AdjustWindowRectEx = AdjustWindowRectEx(
lpRect : RECT*, # RECT* in/out
dwStyle : UInt32, # WINDOW_STYLE
bMenu : Int32, # BOOL
dwExStyle : UInt32 # WINDOW_EX_STYLE
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef AdjustWindowRectExNative = Int32 Function(Pointer<Void>, Uint32, Int32, Uint32);
typedef AdjustWindowRectExDart = int Function(Pointer<Void>, int, int, int);
final AdjustWindowRectEx = DynamicLibrary.open('USER32.dll')
.lookupFunction<AdjustWindowRectExNative, AdjustWindowRectExDart>('AdjustWindowRectEx');
// lpRect : RECT* in/out -> Pointer<Void>
// dwStyle : WINDOW_STYLE -> Uint32
// bMenu : BOOL -> Int32
// dwExStyle : WINDOW_EX_STYLE -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "AdjustWindowRectEx"
c_AdjustWindowRectEx :: Ptr () -> Word32 -> CInt -> Word32 -> IO CInt
-- lpRect : RECT* in/out -> Ptr ()
-- dwStyle : WINDOW_STYLE -> Word32
-- bMenu : BOOL -> CInt
-- dwExStyle : WINDOW_EX_STYLE -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let adjustwindowrectex =
foreign "AdjustWindowRectEx"
((ptr void) @-> uint32_t @-> int32_t @-> uint32_t @-> returning int32_t)
(* lpRect : RECT* in/out -> (ptr void) *)
(* dwStyle : WINDOW_STYLE -> uint32_t *)
(* bMenu : BOOL -> int32_t *)
(* dwExStyle : WINDOW_EX_STYLE -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("AdjustWindowRectEx" adjust-window-rect-ex :convention :stdcall) :int32
(lp-rect :pointer) ; RECT* in/out
(dw-style :uint32) ; WINDOW_STYLE
(b-menu :int32) ; BOOL
(dw-ex-style :uint32)) ; WINDOW_EX_STYLE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $AdjustWindowRectEx = Win32::API::More->new('USER32',
'BOOL AdjustWindowRectEx(LPVOID lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle)');
# my $ret = $AdjustWindowRectEx->Call($lpRect, $dwStyle, $bMenu, $dwExStyle);
# lpRect : RECT* in/out -> LPVOID
# dwStyle : WINDOW_STYLE -> DWORD
# bMenu : BOOL -> BOOL
# dwExStyle : WINDOW_EX_STYLE -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f AdjustWindowRect — クライアント領域から必要なウィンドウ矩形を算出する。
公式の関連項目
- f AdjustWindowRectExForDpi — 指定DPIを考慮しクライアント矩形からウィンドウ矩形を計算する。
- f CreateWindowExW — 拡張スタイル指定でウィンドウを作成する(Unicode)。