AdjustWindowRectExForDpi
関数指定DPIを考慮しクライアント矩形からウィンドウ矩形を計算する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL AdjustWindowRectExForDpi(
RECT* lpRect,
WINDOW_STYLE dwStyle,
BOOL bMenu,
WINDOW_EX_STYLE dwExStyle,
DWORD dpi
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpRect | RECT* | inout |
| dwStyle | WINDOW_STYLE | in |
| bMenu | BOOL | in |
| dwExStyle | WINDOW_EX_STYLE | in |
| dpi | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
BOOL AdjustWindowRectExForDpi(
RECT* lpRect,
WINDOW_STYLE dwStyle,
BOOL bMenu,
WINDOW_EX_STYLE dwExStyle,
DWORD dpi
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool AdjustWindowRectExForDpi(
IntPtr lpRect, // RECT* in/out
uint dwStyle, // WINDOW_STYLE
bool bMenu, // BOOL
uint dwExStyle, // WINDOW_EX_STYLE
uint dpi // DWORD
);<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function AdjustWindowRectExForDpi(
lpRect As IntPtr, ' RECT* in/out
dwStyle As UInteger, ' WINDOW_STYLE
bMenu As Boolean, ' BOOL
dwExStyle As UInteger, ' WINDOW_EX_STYLE
dpi As UInteger ' DWORD
) As Boolean
End Function' lpRect : RECT* in/out
' dwStyle : WINDOW_STYLE
' bMenu : BOOL
' dwExStyle : WINDOW_EX_STYLE
' dpi : DWORD
Declare PtrSafe Function AdjustWindowRectExForDpi Lib "user32" ( _
ByVal lpRect As LongPtr, _
ByVal dwStyle As Long, _
ByVal bMenu As Long, _
ByVal dwExStyle As Long, _
ByVal dpi As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
AdjustWindowRectExForDpi = ctypes.windll.user32.AdjustWindowRectExForDpi
AdjustWindowRectExForDpi.restype = wintypes.BOOL
AdjustWindowRectExForDpi.argtypes = [
ctypes.c_void_p, # lpRect : RECT* in/out
wintypes.DWORD, # dwStyle : WINDOW_STYLE
wintypes.BOOL, # bMenu : BOOL
wintypes.DWORD, # dwExStyle : WINDOW_EX_STYLE
wintypes.DWORD, # dpi : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
AdjustWindowRectExForDpi = Fiddle::Function.new(
lib['AdjustWindowRectExForDpi'],
[
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, # dpi : DWORD
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn AdjustWindowRectExForDpi(
lpRect: *mut RECT, // RECT* in/out
dwStyle: u32, // WINDOW_STYLE
bMenu: i32, // BOOL
dwExStyle: u32, // WINDOW_EX_STYLE
dpi: u32 // DWORD
) -> 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 AdjustWindowRectExForDpi(IntPtr lpRect, uint dwStyle, bool bMenu, uint dwExStyle, uint dpi);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_AdjustWindowRectExForDpi' -Namespace Win32 -PassThru
# $api::AdjustWindowRectExForDpi(lpRect, dwStyle, bMenu, dwExStyle, dpi)#uselib "USER32.dll"
#func global AdjustWindowRectExForDpi "AdjustWindowRectExForDpi" sptr, sptr, sptr, sptr, sptr
; AdjustWindowRectExForDpi varptr(lpRect), dwStyle, bMenu, dwExStyle, dpi ; 戻り値は stat
; lpRect : RECT* in/out -> "sptr"
; dwStyle : WINDOW_STYLE -> "sptr"
; bMenu : BOOL -> "sptr"
; dwExStyle : WINDOW_EX_STYLE -> "sptr"
; dpi : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global AdjustWindowRectExForDpi "AdjustWindowRectExForDpi" var, int, int, int, int ; res = AdjustWindowRectExForDpi(lpRect, dwStyle, bMenu, dwExStyle, dpi) ; lpRect : RECT* in/out -> "var" ; dwStyle : WINDOW_STYLE -> "int" ; bMenu : BOOL -> "int" ; dwExStyle : WINDOW_EX_STYLE -> "int" ; dpi : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global AdjustWindowRectExForDpi "AdjustWindowRectExForDpi" sptr, int, int, int, int ; res = AdjustWindowRectExForDpi(varptr(lpRect), dwStyle, bMenu, dwExStyle, dpi) ; lpRect : RECT* in/out -> "sptr" ; dwStyle : WINDOW_STYLE -> "int" ; bMenu : BOOL -> "int" ; dwExStyle : WINDOW_EX_STYLE -> "int" ; dpi : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL AdjustWindowRectExForDpi(RECT* lpRect, WINDOW_STYLE dwStyle, BOOL bMenu, WINDOW_EX_STYLE dwExStyle, DWORD dpi) #uselib "USER32.dll" #cfunc global AdjustWindowRectExForDpi "AdjustWindowRectExForDpi" var, int, int, int, int ; res = AdjustWindowRectExForDpi(lpRect, dwStyle, bMenu, dwExStyle, dpi) ; lpRect : RECT* in/out -> "var" ; dwStyle : WINDOW_STYLE -> "int" ; bMenu : BOOL -> "int" ; dwExStyle : WINDOW_EX_STYLE -> "int" ; dpi : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL AdjustWindowRectExForDpi(RECT* lpRect, WINDOW_STYLE dwStyle, BOOL bMenu, WINDOW_EX_STYLE dwExStyle, DWORD dpi) #uselib "USER32.dll" #cfunc global AdjustWindowRectExForDpi "AdjustWindowRectExForDpi" intptr, int, int, int, int ; res = AdjustWindowRectExForDpi(varptr(lpRect), dwStyle, bMenu, dwExStyle, dpi) ; lpRect : RECT* in/out -> "intptr" ; dwStyle : WINDOW_STYLE -> "int" ; bMenu : BOOL -> "int" ; dwExStyle : WINDOW_EX_STYLE -> "int" ; dpi : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procAdjustWindowRectExForDpi = user32.NewProc("AdjustWindowRectExForDpi")
)
// lpRect (RECT* in/out), dwStyle (WINDOW_STYLE), bMenu (BOOL), dwExStyle (WINDOW_EX_STYLE), dpi (DWORD)
r1, _, err := procAdjustWindowRectExForDpi.Call(
uintptr(lpRect),
uintptr(dwStyle),
uintptr(bMenu),
uintptr(dwExStyle),
uintptr(dpi),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction AdjustWindowRectExForDpi(
lpRect: Pointer; // RECT* in/out
dwStyle: DWORD; // WINDOW_STYLE
bMenu: BOOL; // BOOL
dwExStyle: DWORD; // WINDOW_EX_STYLE
dpi: DWORD // DWORD
): BOOL; stdcall;
external 'USER32.dll' name 'AdjustWindowRectExForDpi';result := DllCall("USER32\AdjustWindowRectExForDpi"
, "Ptr", lpRect ; RECT* in/out
, "UInt", dwStyle ; WINDOW_STYLE
, "Int", bMenu ; BOOL
, "UInt", dwExStyle ; WINDOW_EX_STYLE
, "UInt", dpi ; DWORD
, "Int") ; return: BOOL●AdjustWindowRectExForDpi(lpRect, dwStyle, bMenu, dwExStyle, dpi) = DLL("USER32.dll", "bool AdjustWindowRectExForDpi(void*, dword, bool, dword, dword)")
# 呼び出し: AdjustWindowRectExForDpi(lpRect, dwStyle, bMenu, dwExStyle, dpi)
# lpRect : RECT* in/out -> "void*"
# dwStyle : WINDOW_STYLE -> "dword"
# bMenu : BOOL -> "bool"
# dwExStyle : WINDOW_EX_STYLE -> "dword"
# dpi : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。