ホーム › UI.WindowsAndMessaging › FindWindowExW
FindWindowExW
関数親や開始位置を指定し子ウィンドウを検索する(Unicode版)。
シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
HWND FindWindowExW(
HWND hWndParent, // optional
HWND hWndChildAfter, // optional
LPCWSTR lpszClass, // optional
LPCWSTR lpszWindow // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hWndParent | HWND | inoptional |
| hWndChildAfter | HWND | inoptional |
| lpszClass | LPCWSTR | inoptional |
| lpszWindow | LPCWSTR | inoptional |
戻り値の型: HWND
各言語での呼び出し定義
// USER32.dll (Unicode / -W)
#include <windows.h>
HWND FindWindowExW(
HWND hWndParent, // optional
HWND hWndChildAfter, // optional
LPCWSTR lpszClass, // optional
LPCWSTR lpszWindow // optional
);[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr FindWindowExW(
IntPtr hWndParent, // HWND optional
IntPtr hWndChildAfter, // HWND optional
[MarshalAs(UnmanagedType.LPWStr)] string lpszClass, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string lpszWindow // LPCWSTR optional
);<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindWindowExW(
hWndParent As IntPtr, ' HWND optional
hWndChildAfter As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPWStr)> lpszClass As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpszWindow As String ' LPCWSTR optional
) As IntPtr
End Function' hWndParent : HWND optional
' hWndChildAfter : HWND optional
' lpszClass : LPCWSTR optional
' lpszWindow : LPCWSTR optional
Declare PtrSafe Function FindWindowExW Lib "user32" ( _
ByVal hWndParent As LongPtr, _
ByVal hWndChildAfter As LongPtr, _
ByVal lpszClass As LongPtr, _
ByVal lpszWindow As LongPtr) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
FindWindowExW = ctypes.windll.user32.FindWindowExW
FindWindowExW.restype = ctypes.c_void_p
FindWindowExW.argtypes = [
wintypes.HANDLE, # hWndParent : HWND optional
wintypes.HANDLE, # hWndChildAfter : HWND optional
wintypes.LPCWSTR, # lpszClass : LPCWSTR optional
wintypes.LPCWSTR, # lpszWindow : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
FindWindowExW = Fiddle::Function.new(
lib['FindWindowExW'],
[
Fiddle::TYPE_VOIDP, # hWndParent : HWND optional
Fiddle::TYPE_VOIDP, # hWndChildAfter : HWND optional
Fiddle::TYPE_VOIDP, # lpszClass : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpszWindow : LPCWSTR optional
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "user32")]
extern "system" {
fn FindWindowExW(
hWndParent: *mut core::ffi::c_void, // HWND optional
hWndChildAfter: *mut core::ffi::c_void, // HWND optional
lpszClass: *const u16, // LPCWSTR optional
lpszWindow: *const u16 // LPCWSTR optional
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr FindWindowExW(IntPtr hWndParent, IntPtr hWndChildAfter, [MarshalAs(UnmanagedType.LPWStr)] string lpszClass, [MarshalAs(UnmanagedType.LPWStr)] string lpszWindow);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_FindWindowExW' -Namespace Win32 -PassThru
# $api::FindWindowExW(hWndParent, hWndChildAfter, lpszClass, lpszWindow)#uselib "USER32.dll"
#func global FindWindowExW "FindWindowExW" wptr, wptr, wptr, wptr
; FindWindowExW hWndParent, hWndChildAfter, lpszClass, lpszWindow ; 戻り値は stat
; hWndParent : HWND optional -> "wptr"
; hWndChildAfter : HWND optional -> "wptr"
; lpszClass : LPCWSTR optional -> "wptr"
; lpszWindow : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global FindWindowExW "FindWindowExW" sptr, sptr, wstr, wstr
; res = FindWindowExW(hWndParent, hWndChildAfter, lpszClass, lpszWindow)
; hWndParent : HWND optional -> "sptr"
; hWndChildAfter : HWND optional -> "sptr"
; lpszClass : LPCWSTR optional -> "wstr"
; lpszWindow : LPCWSTR optional -> "wstr"; HWND FindWindowExW(HWND hWndParent, HWND hWndChildAfter, LPCWSTR lpszClass, LPCWSTR lpszWindow)
#uselib "USER32.dll"
#cfunc global FindWindowExW "FindWindowExW" intptr, intptr, wstr, wstr
; res = FindWindowExW(hWndParent, hWndChildAfter, lpszClass, lpszWindow)
; hWndParent : HWND optional -> "intptr"
; hWndChildAfter : HWND optional -> "intptr"
; lpszClass : LPCWSTR optional -> "wstr"
; lpszWindow : LPCWSTR optional -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procFindWindowExW = user32.NewProc("FindWindowExW")
)
// hWndParent (HWND optional), hWndChildAfter (HWND optional), lpszClass (LPCWSTR optional), lpszWindow (LPCWSTR optional)
r1, _, err := procFindWindowExW.Call(
uintptr(hWndParent),
uintptr(hWndChildAfter),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszClass))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszWindow))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HWNDfunction FindWindowExW(
hWndParent: THandle; // HWND optional
hWndChildAfter: THandle; // HWND optional
lpszClass: PWideChar; // LPCWSTR optional
lpszWindow: PWideChar // LPCWSTR optional
): THandle; stdcall;
external 'USER32.dll' name 'FindWindowExW';result := DllCall("USER32\FindWindowExW"
, "Ptr", hWndParent ; HWND optional
, "Ptr", hWndChildAfter ; HWND optional
, "WStr", lpszClass ; LPCWSTR optional
, "WStr", lpszWindow ; LPCWSTR optional
, "Ptr") ; return: HWND●FindWindowExW(hWndParent, hWndChildAfter, lpszClass, lpszWindow) = DLL("USER32.dll", "void* FindWindowExW(void*, void*, char*, char*)")
# 呼び出し: FindWindowExW(hWndParent, hWndChildAfter, lpszClass, lpszWindow)
# hWndParent : HWND optional -> "void*"
# hWndChildAfter : HWND optional -> "void*"
# lpszClass : LPCWSTR optional -> "char*"
# lpszWindow : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。