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

CalculatePopupWindowPosition

関数
アンカー点と除外領域からポップアップ表示位置を算出する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 7 以降

シグネチャ

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

BOOL CalculatePopupWindowPosition(
    const POINT* anchorPoint,
    const SIZE* windowSize,
    DWORD flags,
    RECT* excludeRect,   // optional
    RECT* popupWindowPosition
);

パラメーター

名前方向
anchorPointPOINT*in
windowSizeSIZE*in
flagsDWORDin
excludeRectRECT*inoptional
popupWindowPositionRECT*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL CalculatePopupWindowPosition(
    const POINT* anchorPoint,
    const SIZE* windowSize,
    DWORD flags,
    RECT* excludeRect,   // optional
    RECT* popupWindowPosition
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CalculatePopupWindowPosition(
    IntPtr anchorPoint,   // POINT*
    IntPtr windowSize,   // SIZE*
    uint flags,   // DWORD
    IntPtr excludeRect,   // RECT* optional
    IntPtr popupWindowPosition   // RECT* out
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CalculatePopupWindowPosition(
    anchorPoint As IntPtr,   ' POINT*
    windowSize As IntPtr,   ' SIZE*
    flags As UInteger,   ' DWORD
    excludeRect As IntPtr,   ' RECT* optional
    popupWindowPosition As IntPtr   ' RECT* out
) As Boolean
End Function
' anchorPoint : POINT*
' windowSize : SIZE*
' flags : DWORD
' excludeRect : RECT* optional
' popupWindowPosition : RECT* out
Declare PtrSafe Function CalculatePopupWindowPosition Lib "user32" ( _
    ByVal anchorPoint As LongPtr, _
    ByVal windowSize As LongPtr, _
    ByVal flags As Long, _
    ByVal excludeRect As LongPtr, _
    ByVal popupWindowPosition As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition
CalculatePopupWindowPosition.restype = wintypes.BOOL
CalculatePopupWindowPosition.argtypes = [
    ctypes.c_void_p,  # anchorPoint : POINT*
    ctypes.c_void_p,  # windowSize : SIZE*
    wintypes.DWORD,  # flags : DWORD
    ctypes.c_void_p,  # excludeRect : RECT* optional
    ctypes.c_void_p,  # popupWindowPosition : RECT* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procCalculatePopupWindowPosition = user32.NewProc("CalculatePopupWindowPosition")
)

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