Capture all Windows handles (HWND) and process IDs

Some functions like imagegrabwindow require the HWND to specify which window you want to copy.

Some functions like imagegrabwindow require the HWND (an integer value) to specify which window you want to copy. No problem if you start the process with $x=new COM(...) like in the examples at php.net. But how do you get the HWND of windows already opened? I've struggled with com_get_active_object but did not get too far. That's why I've written and compiled a C++ tool for collecting all active HWNDs and process IDs which can be accessed from PHP via the Windows shell. This opens many possibilities. Download GETHWND.ZIP Access via PHP $x=shell_exec("gethwnd.exe"); Output structure: HWND : Window Name : ProcessID; $x will be a string containing the whole list like 0x40492;Perseus #1:472;0x405c2;SysFader:473;...

Code samples

Listhwnd.php

Creates a table of all named HWNDs and Process IDs with links for a snapshot. Please note that not all the HWND are actually valid for snapsnots.

snap.php

performs the snapshot.

gethwnd.php

This function returns the HWND if you hand over a window name (in this case the first 10 chars only).

Source in C++: