Showing posts with label process. Show all posts
Showing posts with label process. Show all posts

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
Solution: GetProcessId()

3)
HAVE: Window handle, NEED: Process ID
Solution: GetWindowThreadProcessId()

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

5)
HAVE: Process ID, NEED: Window handle
Solution: EnumWindows(), 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)