Wednesday, June 19, 2013

Windows API: The relationship between Process, Handle and Windows

1)
HAVE: Process ID, NEED: Process handle
Solution
OpenProcess()

2)
HAVE: Process handle, NEED: Process ID
SolutionGetProcessId()

3)
HAVE: Window handle, NEED: Process ID
SolutionGetWindowThreadProcessId()

4)
HAVE: Window handle, NEED: Process handle
Solution: Use 3) and then 1)

5)
HAVE: Process ID, NEED: Window handle
SolutionEnumWindows(), then in the callback function do 3) and check if it matches your process ID.

6)
HAVE: Process handle, NEED: Window handle
Solution: 2) and then 5)