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

GetWindow

関数
指定ウィンドウと関係のあるウィンドウのハンドルを取得する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

HWND GetWindow(
    HWND hWnd,
    GET_WINDOW_CMD uCmd
);

パラメーター

名前方向
hWndHWNDin
uCmdGET_WINDOW_CMDin

戻り値の型: HWND

各言語での呼び出し定義

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

HWND GetWindow(
    HWND hWnd,
    GET_WINDOW_CMD uCmd
);
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr GetWindow(
    IntPtr hWnd,   // HWND
    uint uCmd   // GET_WINDOW_CMD
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetWindow(
    hWnd As IntPtr,   ' HWND
    uCmd As UInteger   ' GET_WINDOW_CMD
) As IntPtr
End Function
' hWnd : HWND
' uCmd : GET_WINDOW_CMD
Declare PtrSafe Function GetWindow Lib "user32" ( _
    ByVal hWnd As LongPtr, _
    ByVal uCmd As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetWindow = ctypes.windll.user32.GetWindow
GetWindow.restype = ctypes.c_void_p
GetWindow.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    wintypes.DWORD,  # uCmd : GET_WINDOW_CMD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
GetWindow = Fiddle::Function.new(
  lib['GetWindow'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    -Fiddle::TYPE_INT,  # uCmd : GET_WINDOW_CMD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "user32")]
extern "system" {
    fn GetWindow(
        hWnd: *mut core::ffi::c_void,  // HWND
        uCmd: u32  // GET_WINDOW_CMD
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", SetLastError = true)]
public static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetWindow' -Namespace Win32 -PassThru
# $api::GetWindow(hWnd, uCmd)
#uselib "USER32.dll"
#func global GetWindow "GetWindow" sptr, sptr
; GetWindow hWnd, uCmd   ; 戻り値は stat
; hWnd : HWND -> "sptr"
; uCmd : GET_WINDOW_CMD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global GetWindow "GetWindow" sptr, int
; res = GetWindow(hWnd, uCmd)
; hWnd : HWND -> "sptr"
; uCmd : GET_WINDOW_CMD -> "int"
; HWND GetWindow(HWND hWnd, GET_WINDOW_CMD uCmd)
#uselib "USER32.dll"
#cfunc global GetWindow "GetWindow" intptr, int
; res = GetWindow(hWnd, uCmd)
; hWnd : HWND -> "intptr"
; uCmd : GET_WINDOW_CMD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetWindow = user32.NewProc("GetWindow")
)

// hWnd (HWND), uCmd (GET_WINDOW_CMD)
r1, _, err := procGetWindow.Call(
	uintptr(hWnd),
	uintptr(uCmd),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HWND
function GetWindow(
  hWnd: THandle;   // HWND
  uCmd: DWORD   // GET_WINDOW_CMD
): THandle; stdcall;
  external 'USER32.dll' name 'GetWindow';
result := DllCall("USER32\GetWindow"
    , "Ptr", hWnd   ; HWND
    , "UInt", uCmd   ; GET_WINDOW_CMD
    , "Ptr")   ; return: HWND
●GetWindow(hWnd, uCmd) = DLL("USER32.dll", "void* GetWindow(void*, dword)")
# 呼び出し: GetWindow(hWnd, uCmd)
# hWnd : HWND -> "void*"
# uCmd : GET_WINDOW_CMD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。