Is it possible to get info between HWND and Process handle?
-
I need: *) Get Handle of Main Window from process handle (I know the process handle). or: *) Get process info (i.e. process ID or handle) from a Window handle (I know the window handle). any solution for 2 questions above is helpful - first is prefered. thx includeh10
-
I need: *) Get Handle of Main Window from process handle (I know the process handle). or: *) Get process info (i.e. process ID or handle) from a Window handle (I know the window handle). any solution for 2 questions above is helpful - first is prefered. thx includeh10
Answer to your 2. question:
// assuming that you have window handle // get process ID from window handle DWORD dwProcessId = 0; GetWindowThreadProcessId (hWnd, &dwProcessId); // get process handle from process ID HANDLE hProcess = NULL; hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, dwProcessId);
-
I need: *) Get Handle of Main Window from process handle (I know the process handle). or: *) Get process info (i.e. process ID or handle) from a Window handle (I know the window handle). any solution for 2 questions above is helpful - first is prefered. thx includeh10
1. - Use GetProcessId() to get process id from process handle. - Use EnumWindows() to look at each top-level window. - For each top-level window call GetWindowThreadProcessId() to get the thread id and process id that was used to create the window. - Break when you find a top-level window that was created by the specified process handle/id. 2. - Use GetWindowThreadProcessId() to get the thread id and process id that was used to create the window. ...cmk Save the whales - collect the whole set