从HWND获取窗口信息

Getting Window info from its HWND

本文关键字:信息 窗口 获取 HWND      更新时间:2023-10-16

我有这样的代码:

HWND WindowHandle;
WindowHandle = FindWindowA( WindowClass, WindowName );
if( WindowHandle != NULL)
{
     // here I want to populate a listbox with the window's information like
     // its process name and PID, executable file name,  and its window title.
}

我已经知道如何获得窗口标题,与SendMessage();WM_GETTEXT,但我想知道如何获得它的进程名和PID,以及可执行文件的位置和名称。

有人能帮我吗?

请注意,我正在使用c++ MFC。

Windows提供了一个名为GetWindowThreadProcessId的函数。

听起来像是你想要的。

免责声明:我没有用过

您可以在PROCESS_INFORMATION中找到PID。只需声明:PROCESS_INFORMATION pi,并像这样访问PID: pi.hProcesss pi.dwProcessId