ホーム › UI.WindowsAndMessaging › GetAncestor
GetAncestor
関数指定ウィンドウの親や先祖ウィンドウのハンドルを取得する。
シグネチャ
// USER32.dll
#include <windows.h>
HWND GetAncestor(
HWND hwnd,
GET_ANCESTOR_FLAGS gaFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hwnd | HWND | in |
| gaFlags | GET_ANCESTOR_FLAGS | in |
戻り値の型: HWND
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
HWND GetAncestor(
HWND hwnd,
GET_ANCESTOR_FLAGS gaFlags
);[DllImport("USER32.dll", ExactSpelling = true)]
static extern IntPtr GetAncestor(
IntPtr hwnd, // HWND
uint gaFlags // GET_ANCESTOR_FLAGS
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function GetAncestor(
hwnd As IntPtr, ' HWND
gaFlags As UInteger ' GET_ANCESTOR_FLAGS
) As IntPtr
End Function' hwnd : HWND
' gaFlags : GET_ANCESTOR_FLAGS
Declare PtrSafe Function GetAncestor Lib "user32" ( _
ByVal hwnd As LongPtr, _
ByVal gaFlags As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetAncestor = ctypes.windll.user32.GetAncestor
GetAncestor.restype = ctypes.c_void_p
GetAncestor.argtypes = [
wintypes.HANDLE, # hwnd : HWND
wintypes.DWORD, # gaFlags : GET_ANCESTOR_FLAGS
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
GetAncestor = Fiddle::Function.new(
lib['GetAncestor'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND
-Fiddle::TYPE_INT, # gaFlags : GET_ANCESTOR_FLAGS
],
Fiddle::TYPE_VOIDP)#[link(name = "user32")]
extern "system" {
fn GetAncestor(
hwnd: *mut core::ffi::c_void, // HWND
gaFlags: u32 // GET_ANCESTOR_FLAGS
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll")]
public static extern IntPtr GetAncestor(IntPtr hwnd, uint gaFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetAncestor' -Namespace Win32 -PassThru
# $api::GetAncestor(hwnd, gaFlags)#uselib "USER32.dll"
#func global GetAncestor "GetAncestor" sptr, sptr
; GetAncestor hwnd, gaFlags ; 戻り値は stat
; hwnd : HWND -> "sptr"
; gaFlags : GET_ANCESTOR_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global GetAncestor "GetAncestor" sptr, int
; res = GetAncestor(hwnd, gaFlags)
; hwnd : HWND -> "sptr"
; gaFlags : GET_ANCESTOR_FLAGS -> "int"; HWND GetAncestor(HWND hwnd, GET_ANCESTOR_FLAGS gaFlags)
#uselib "USER32.dll"
#cfunc global GetAncestor "GetAncestor" intptr, int
; res = GetAncestor(hwnd, gaFlags)
; hwnd : HWND -> "intptr"
; gaFlags : GET_ANCESTOR_FLAGS -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procGetAncestor = user32.NewProc("GetAncestor")
)
// hwnd (HWND), gaFlags (GET_ANCESTOR_FLAGS)
r1, _, err := procGetAncestor.Call(
uintptr(hwnd),
uintptr(gaFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HWNDfunction GetAncestor(
hwnd: THandle; // HWND
gaFlags: DWORD // GET_ANCESTOR_FLAGS
): THandle; stdcall;
external 'USER32.dll' name 'GetAncestor';result := DllCall("USER32\GetAncestor"
, "Ptr", hwnd ; HWND
, "UInt", gaFlags ; GET_ANCESTOR_FLAGS
, "Ptr") ; return: HWND●GetAncestor(hwnd, gaFlags) = DLL("USER32.dll", "void* GetAncestor(void*, dword)")
# 呼び出し: GetAncestor(hwnd, gaFlags)
# hwnd : HWND -> "void*"
# gaFlags : GET_ANCESTOR_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。