ホーム › UI.WindowsAndMessaging › CalculatePopupWindowPosition
CalculatePopupWindowPosition
関数アンカー点と除外領域からポップアップ表示位置を算出する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL CalculatePopupWindowPosition(
const POINT* anchorPoint,
const SIZE* windowSize,
DWORD flags,
RECT* excludeRect, // optional
RECT* popupWindowPosition
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| anchorPoint | POINT* | in | 指定するアンカーポイント。 | ||||||||||||||||||||||||||
| windowSize | SIZE* | in | 指定するウィンドウのサイズ。 | ||||||||||||||||||||||||||
| flags | DWORD | in | 次のいずれかのフラグを使用して、関数がポップアップウィンドウを水平方向および垂直方向にどのように配置するかを指定します。これらのフラグは、TrackPopupMenuEx 関数の垂直方向および水平方向の配置フラグと同じです。 次のいずれかのフラグを使用して、関数がポップアップウィンドウを水平方向にどのように配置するかを指定します。
次のいずれかのフラグを使用して、関数がポップアップウィンドウを垂直方向にどのように配置するかを指定します。
次のいずれかのフラグを使用して、水平方向と垂直方向のどちらの配置を優先するかを指定します。
次のフラグは Windows 7 以降で使用できます。
| ||||||||||||||||||||||||||
| excludeRect | RECT* | inoptional | 除外矩形を指定する構造体へのポインター。NULL を指定できます。 | ||||||||||||||||||||||||||
| popupWindowPosition | RECT* | out | ポップアップウィンドウの位置を指定する構造体へのポインター。 |
戻り値の型: BOOL
公式ドキュメント
指定したアンカーポイント、ポップアップウィンドウのサイズ、フラグ、および省略可能な除外矩形を使用して、適切なポップアップウィンドウの位置を計算します。
戻り値
Type: BOOL
関数が成功した場合は TRUE を返します。それ以外の場合は FALSE を返します。拡張エラー情報を取得するには、GetLastError を呼び出します。
解説(Remarks)
TPM_WORKAREA は、TrackPopupMenu 関数および TrackPopupMenuEx 関数でサポートされています。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 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 <MarshalAs(UnmanagedType.Bool)> 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 方式にも切替可。#uselib "USER32.dll" #cfunc global CalculatePopupWindowPosition "CalculatePopupWindowPosition" sptr, sptr, int, sptr, sptr ; res = CalculatePopupWindowPosition(varptr(anchorPoint), varptr(windowSize), flags, varptr(excludeRect), varptr(popupWindowPosition)) ; anchorPoint : POINT* -> "sptr" ; windowSize : SIZE* -> "sptr" ; flags : DWORD -> "int" ; excludeRect : RECT* optional -> "sptr" ; popupWindowPosition : RECT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; BOOL CalculatePopupWindowPosition(POINT* anchorPoint, SIZE* windowSize, DWORD flags, RECT* excludeRect, RECT* popupWindowPosition) #uselib "USER32.dll" #cfunc global CalculatePopupWindowPosition "CalculatePopupWindowPosition" intptr, intptr, int, intptr, intptr ; res = CalculatePopupWindowPosition(varptr(anchorPoint), varptr(windowSize), flags, varptr(excludeRect), varptr(popupWindowPosition)) ; anchorPoint : POINT* -> "intptr" ; windowSize : SIZE* -> "intptr" ; flags : DWORD -> "int" ; excludeRect : RECT* optional -> "intptr" ; popupWindowPosition : RECT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。const std = @import("std");
extern "user32" fn CalculatePopupWindowPosition(
anchorPoint: [*c]POINT, // POINT*
windowSize: [*c]SIZE, // SIZE*
flags: u32, // DWORD
excludeRect: [*c]RECT, // RECT* optional
popupWindowPosition: [*c]RECT // RECT* out
) callconv(std.os.windows.WINAPI) i32;proc CalculatePopupWindowPosition(
anchorPoint: ptr POINT, # POINT*
windowSize: ptr SIZE, # SIZE*
flags: uint32, # DWORD
excludeRect: ptr RECT, # RECT* optional
popupWindowPosition: ptr RECT # RECT* out
): int32 {.importc: "CalculatePopupWindowPosition", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int CalculatePopupWindowPosition(
POINT* anchorPoint, // POINT*
SIZE* windowSize, // SIZE*
uint flags, // DWORD
RECT* excludeRect, // RECT* optional
RECT* popupWindowPosition // RECT* out
);ccall((:CalculatePopupWindowPosition, "USER32.dll"), stdcall, Int32,
(Ptr{POINT}, Ptr{SIZE}, UInt32, Ptr{RECT}, Ptr{RECT}),
anchorPoint, windowSize, flags, excludeRect, popupWindowPosition)
# anchorPoint : POINT* -> Ptr{POINT}
# windowSize : SIZE* -> Ptr{SIZE}
# flags : DWORD -> UInt32
# excludeRect : RECT* optional -> Ptr{RECT}
# popupWindowPosition : RECT* out -> Ptr{RECT}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CalculatePopupWindowPosition(
void* anchorPoint,
void* windowSize,
uint32_t flags,
void* excludeRect,
void* popupWindowPosition);
]]
local user32 = ffi.load("user32")
-- user32.CalculatePopupWindowPosition(anchorPoint, windowSize, flags, excludeRect, popupWindowPosition)
-- anchorPoint : POINT*
-- windowSize : SIZE*
-- flags : DWORD
-- excludeRect : RECT* optional
-- popupWindowPosition : RECT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const CalculatePopupWindowPosition = lib.func('__stdcall', 'CalculatePopupWindowPosition', 'int32_t', ['void *', 'void *', 'uint32_t', 'void *', 'void *']);
// CalculatePopupWindowPosition(anchorPoint, windowSize, flags, excludeRect, popupWindowPosition)
// anchorPoint : POINT* -> 'void *'
// windowSize : SIZE* -> 'void *'
// flags : DWORD -> 'uint32_t'
// excludeRect : RECT* optional -> 'void *'
// popupWindowPosition : RECT* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
CalculatePopupWindowPosition: { parameters: ["pointer", "pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CalculatePopupWindowPosition(anchorPoint, windowSize, flags, excludeRect, popupWindowPosition)
// anchorPoint : POINT* -> "pointer"
// windowSize : SIZE* -> "pointer"
// flags : DWORD -> "u32"
// excludeRect : RECT* optional -> "pointer"
// popupWindowPosition : RECT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CalculatePopupWindowPosition(
void* anchorPoint,
void* windowSize,
uint32_t flags,
void* excludeRect,
void* popupWindowPosition);
C, "USER32.dll");
// $ffi->CalculatePopupWindowPosition(anchorPoint, windowSize, flags, excludeRect, popupWindowPosition);
// anchorPoint : POINT*
// windowSize : SIZE*
// flags : DWORD
// excludeRect : RECT* optional
// popupWindowPosition : RECT* out
// 構造体/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 CalculatePopupWindowPosition(
Pointer anchorPoint, // POINT*
Pointer windowSize, // SIZE*
int flags, // DWORD
Pointer excludeRect, // RECT* optional
Pointer popupWindowPosition // RECT* out
);
}@[Link("user32")]
lib LibUSER32
fun CalculatePopupWindowPosition = CalculatePopupWindowPosition(
anchorPoint : POINT*, # POINT*
windowSize : SIZE*, # SIZE*
flags : UInt32, # DWORD
excludeRect : RECT*, # RECT* optional
popupWindowPosition : RECT* # RECT* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CalculatePopupWindowPositionNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Void>);
typedef CalculatePopupWindowPositionDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Void>, Pointer<Void>);
final CalculatePopupWindowPosition = DynamicLibrary.open('USER32.dll')
.lookupFunction<CalculatePopupWindowPositionNative, CalculatePopupWindowPositionDart>('CalculatePopupWindowPosition');
// anchorPoint : POINT* -> Pointer<Void>
// windowSize : SIZE* -> Pointer<Void>
// flags : DWORD -> Uint32
// excludeRect : RECT* optional -> Pointer<Void>
// popupWindowPosition : RECT* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CalculatePopupWindowPosition"
c_CalculatePopupWindowPosition :: Ptr () -> Ptr () -> Word32 -> Ptr () -> Ptr () -> IO CInt
-- anchorPoint : POINT* -> Ptr ()
-- windowSize : SIZE* -> Ptr ()
-- flags : DWORD -> Word32
-- excludeRect : RECT* optional -> Ptr ()
-- popupWindowPosition : RECT* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let calculatepopupwindowposition =
foreign "CalculatePopupWindowPosition"
((ptr void) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* anchorPoint : POINT* -> (ptr void) *)
(* windowSize : SIZE* -> (ptr void) *)
(* flags : DWORD -> uint32_t *)
(* excludeRect : RECT* optional -> (ptr void) *)
(* popupWindowPosition : RECT* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("CalculatePopupWindowPosition" calculate-popup-window-position :convention :stdcall) :int32
(anchor-point :pointer) ; POINT*
(window-size :pointer) ; SIZE*
(flags :uint32) ; DWORD
(exclude-rect :pointer) ; RECT* optional
(popup-window-position :pointer)) ; RECT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CalculatePopupWindowPosition = Win32::API::More->new('USER32',
'BOOL CalculatePopupWindowPosition(LPVOID anchorPoint, LPVOID windowSize, DWORD flags, LPVOID excludeRect, LPVOID popupWindowPosition)');
# my $ret = $CalculatePopupWindowPosition->Call($anchorPoint, $windowSize, $flags, $excludeRect, $popupWindowPosition);
# anchorPoint : POINT* -> LPVOID
# windowSize : SIZE* -> LPVOID
# flags : DWORD -> DWORD
# excludeRect : RECT* optional -> LPVOID
# popupWindowPosition : RECT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f TrackPopupMenu — 指定位置にポップアップメニューを表示し選択を追跡する。
- f TrackPopupMenuEx — 拡張パラメータ付きでポップアップメニューを表示し追跡する。