c++ find process handle without FindWindow function

4.4k views Asked by At

i tryied to find the process handle,

HWND handle = FindWindow(0 ,TEXT("window title"));

i need window title
Let's say that I have tow process with the same title
so i want to make something like:

for each p as process in process.getProcessByName("notepad")

if process.processname = "notepad" then

handle = p.handle

exit for

end if

next
1

There are 1 answers

0
Remy Lebeau On

You have to enumerate the running processes yourself looking for the names manually. You can do that using either:

1) CreateToolhelp32Snapshot(), Process32First(), and Process32Next(). See MSDN for an example:

Taking a Snapshot and Viewing Processes

2) EnumProcesses(), OpenProcess(), EnumProcessModules() and GetModuleBaseName(). See MSDN for an example:

Enumerating All Processes

3) use WMI to enumerate the items in the Win32_Process collection.