Is it possible to get the HWND
from a window by a process name?
The name of the window changes on every restart (random windowname), like this:
I just found something to get it by window name.
Is it possible to get the HWND
from a window by a process name?
The name of the window changes on every restart (random windowname), like this:
I just found something to get it by window name.
The connection between processes and windows is not obvious. First of all, a process can have several windows. Second, it looks like Windows APIs do not provide a method to look up windows based on a process (which I find weird, given your screenshot shows just that).
However, you can go through all open windows and filter based on a process. See this question with an elaborate answer on how to do it: Find Window and change it's name
I have found this solution, but I get multiple HWNDs for the one process ID
#include <Windows.h>
void GetAllWindowsFromProcessID(DWORD searchPID, std::vector <HWND> &wnds)
{
HWND hCurWnd = NULL;
do
{
hCurWnd = FindWindowEx(NULL, hCurWnd, NULL, NULL);
DWORD processID = 0;
GetWindowThreadProcessId(hCurWnd, &processID);
if (searchPID == processID)
{
wnds.push_back(hCurWnd);
}
} while (hCurWnd != NULL);
}
int main()
{
DWORD PID = 0x00001D7C;
std::vector<HWND> HWND_List;
GetAllWindowsFromProcessID(PID, HWND_List);
return 0;
}