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

FindWindowExA

関数
親や開始位置を指定し子ウィンドウを検索する(ANSI版)。
DLLUSER32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (ANSI / -A)
#include <windows.h>

HWND FindWindowExA(
    HWND hWndParent,   // optional
    HWND hWndChildAfter,   // optional
    LPCSTR lpszClass,   // optional
    LPCSTR lpszWindow   // optional
);

パラメーター

名前方向
hWndParentHWNDinoptional
hWndChildAfterHWNDinoptional
lpszClassLPCSTRinoptional
lpszWindowLPCSTRinoptional

戻り値の型: HWND

各言語での呼び出し定義

// USER32.dll  (ANSI / -A)
#include <windows.h>

HWND FindWindowExA(
    HWND hWndParent,   // optional
    HWND hWndChildAfter,   // optional
    LPCSTR lpszClass,   // optional
    LPCSTR lpszWindow   // optional
);
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr FindWindowExA(
    IntPtr hWndParent,   // HWND optional
    IntPtr hWndChildAfter,   // HWND optional
    [MarshalAs(UnmanagedType.LPStr)] string lpszClass,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string lpszWindow   // LPCSTR optional
);
<DllImport("USER32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindWindowExA(
    hWndParent As IntPtr,   ' HWND optional
    hWndChildAfter As IntPtr,   ' HWND optional
    <MarshalAs(UnmanagedType.LPStr)> lpszClass As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> lpszWindow As String   ' LPCSTR optional
) As IntPtr
End Function
' hWndParent : HWND optional
' hWndChildAfter : HWND optional
' lpszClass : LPCSTR optional
' lpszWindow : LPCSTR optional
Declare PtrSafe Function FindWindowExA Lib "user32" ( _
    ByVal hWndParent As LongPtr, _
    ByVal hWndChildAfter As LongPtr, _
    ByVal lpszClass As String, _
    ByVal lpszWindow As String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

FindWindowExA = ctypes.windll.user32.FindWindowExA
FindWindowExA.restype = ctypes.c_void_p
FindWindowExA.argtypes = [
    wintypes.HANDLE,  # hWndParent : HWND optional
    wintypes.HANDLE,  # hWndChildAfter : HWND optional
    wintypes.LPCSTR,  # lpszClass : LPCSTR optional
    wintypes.LPCSTR,  # lpszWindow : LPCSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
FindWindowExA = Fiddle::Function.new(
  lib['FindWindowExA'],
  [
    Fiddle::TYPE_VOIDP,  # hWndParent : HWND optional
    Fiddle::TYPE_VOIDP,  # hWndChildAfter : HWND optional
    Fiddle::TYPE_VOIDP,  # lpszClass : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lpszWindow : LPCSTR optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "user32")]
extern "system" {
    fn FindWindowExA(
        hWndParent: *mut core::ffi::c_void,  // HWND optional
        hWndChildAfter: *mut core::ffi::c_void,  // HWND optional
        lpszClass: *const u8,  // LPCSTR optional
        lpszWindow: *const u8  // LPCSTR optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr FindWindowExA(IntPtr hWndParent, IntPtr hWndChildAfter, [MarshalAs(UnmanagedType.LPStr)] string lpszClass, [MarshalAs(UnmanagedType.LPStr)] string lpszWindow);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_FindWindowExA' -Namespace Win32 -PassThru
# $api::FindWindowExA(hWndParent, hWndChildAfter, lpszClass, lpszWindow)
#uselib "USER32.dll"
#func global FindWindowExA "FindWindowExA" sptr, sptr, sptr, sptr
; FindWindowExA hWndParent, hWndChildAfter, lpszClass, lpszWindow   ; 戻り値は stat
; hWndParent : HWND optional -> "sptr"
; hWndChildAfter : HWND optional -> "sptr"
; lpszClass : LPCSTR optional -> "sptr"
; lpszWindow : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global FindWindowExA "FindWindowExA" sptr, sptr, str, str
; res = FindWindowExA(hWndParent, hWndChildAfter, lpszClass, lpszWindow)
; hWndParent : HWND optional -> "sptr"
; hWndChildAfter : HWND optional -> "sptr"
; lpszClass : LPCSTR optional -> "str"
; lpszWindow : LPCSTR optional -> "str"
; HWND FindWindowExA(HWND hWndParent, HWND hWndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
#uselib "USER32.dll"
#cfunc global FindWindowExA "FindWindowExA" intptr, intptr, str, str
; res = FindWindowExA(hWndParent, hWndChildAfter, lpszClass, lpszWindow)
; hWndParent : HWND optional -> "intptr"
; hWndChildAfter : HWND optional -> "intptr"
; lpszClass : LPCSTR optional -> "str"
; lpszWindow : LPCSTR optional -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procFindWindowExA = user32.NewProc("FindWindowExA")
)

// hWndParent (HWND optional), hWndChildAfter (HWND optional), lpszClass (LPCSTR optional), lpszWindow (LPCSTR optional)
r1, _, err := procFindWindowExA.Call(
	uintptr(hWndParent),
	uintptr(hWndChildAfter),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszClass))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszWindow))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HWND
function FindWindowExA(
  hWndParent: THandle;   // HWND optional
  hWndChildAfter: THandle;   // HWND optional
  lpszClass: PAnsiChar;   // LPCSTR optional
  lpszWindow: PAnsiChar   // LPCSTR optional
): THandle; stdcall;
  external 'USER32.dll' name 'FindWindowExA';
result := DllCall("USER32\FindWindowExA"
    , "Ptr", hWndParent   ; HWND optional
    , "Ptr", hWndChildAfter   ; HWND optional
    , "AStr", lpszClass   ; LPCSTR optional
    , "AStr", lpszWindow   ; LPCSTR optional
    , "Ptr")   ; return: HWND
●FindWindowExA(hWndParent, hWndChildAfter, lpszClass, lpszWindow) = DLL("USER32.dll", "void* FindWindowExA(void*, void*, char*, char*)")
# 呼び出し: FindWindowExA(hWndParent, hWndChildAfter, lpszClass, lpszWindow)
# hWndParent : HWND optional -> "void*"
# hWndChildAfter : HWND optional -> "void*"
# lpszClass : LPCSTR optional -> "char*"
# lpszWindow : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。