Getting the process that owns the window
-
Found some additional info on getting the exe name from the process ID See the second Q/A here[^] Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Found some additional info on getting the exe name from the process ID See the second Q/A here[^] Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Mark Salsbery wrote:
I'd guess that task manager uses WMI.
Nah... probably DDE... so a couple tin cans and some string. But you can't find the documentation online because it was chiseled into stone tablets.
I had to sign a NDA for Microsoft so I'm not allowed to talk about The Stone Tablets.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I've thought of getting the handle, then enumerating processes and trying to enumate windows for those processes and matching the handles, but that's seems just so far fetched. Isn't there an easier way?
The link I posted shows a way to do it without enumerating. The caveat is it's for NT 4+. For Windows versions back to 95, it seems to me it would be simpler to get the process ID from the window handle and enumerate the processes until you find the matching ID. Much less work than enumerating the processes AND enumerating the windows for each process! Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
If you persist in this reading of the documentation I am going to suggest that Maunder revoke your membership. or NOT FAIR! Getting answers from the documentation! It's not like we all have access to that!
:laugh:
led mike wrote:
It's not like we all have access to that!
Thank goodness! it's job security!!
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
The link I posted shows a way to do it without enumerating. The caveat is it's for NT 4+. For Windows versions back to 95, it seems to me it would be simpler to get the process ID from the window handle and enumerate the processes until you find the matching ID. Much less work than enumerating the processes AND enumerating the windows for each process! Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Sure, I'll use it if there's no better way, but it's pretty much the same - get the handle and compare it to the process's handles, if I read correctly. There has to be a way to get a process handle from a window handle. A process must own that window, and it's possible to enumerate a process's windows, so why not the other way?
-
Sure, I'll use it if there's no better way, but it's pretty much the same - get the handle and compare it to the process's handles, if I read correctly. There has to be a way to get a process handle from a window handle. A process must own that window, and it's possible to enumerate a process's windows, so why not the other way?
Tydia-kun wrote:
There has to be a way to get a process handle from a window handle.
See the first sentence in my first reply[^] To get a handle from the ID, open one with OpenProcess(). led mike's not going to like this, but there's a whole bunch of process-related APIs to play with - they're documented ... Process and Thread Functions[^] Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Sure, I'll use it if there's no better way, but it's pretty much the same - get the handle and compare it to the process's handles, if I read correctly. There has to be a way to get a process handle from a window handle. A process must own that window, and it's possible to enumerate a process's windows, so why not the other way?
Also, your first post, to me, implied you had the window handle already. That's why I ask why enumerate every window when you have it already? Don't you just need the information for the process that created that window? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Tydia-kun wrote:
There has to be a way to get a process handle from a window handle.
See the first sentence in my first reply[^] To get a handle from the ID, open one with OpenProcess(). led mike's not going to like this, but there's a whole bunch of process-related APIs to play with - they're documented ... Process and Thread Functions[^] Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
I have a window handle, but not a process id or process handle, because I don't know how to get either from a WINDOW handle. I know there's lots of functions and I've looked over them once or twice, but there's no function that returns a process id or handle from a window handle from what I can see.
-
Also, your first post, to me, implied you had the window handle already. That's why I ask why enumerate every window when you have it already? Don't you just need the information for the process that created that window? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Yes, I have the hwnd. But as I mentioned, unless there's a way to get the process id or handle from a hwnd, I need to enumerate all processes and enumerate all their windows and compare those handles to the handle for the window I want to find, thus finding the owning process. Get me?
-
I have a window handle, but not a process id or process handle, because I don't know how to get either from a WINDOW handle. I know there's lots of functions and I've looked over them once or twice, but there's no function that returns a process id or handle from a window handle from what I can see.
Tydia-kun wrote:
but there's no function that returns a process id or handle from a window handle
Mark wrote a couple times:
GetWindowThreadProcessId
Once again, it was in the first reply, first sentence :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Yes, I have the hwnd. But as I mentioned, unless there's a way to get the process id or handle from a hwnd, I need to enumerate all processes and enumerate all their windows and compare those handles to the handle for the window I want to find, thus finding the owning process. Get me?
GetWindowThreadProcessId() GetWindowThreadProcessId() GetWindowThreadProcessId()
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Tydia-kun wrote:
but there's no function that returns a process id or handle from a window handle
Mark wrote a couple times:
GetWindowThreadProcessId
Once again, it was in the first reply, first sentence :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I really must have missed it or interpreted the message wrong. Thanks again. This non-linear way of showing posts in this forum really makes a mess out of things -_-
:) No problem!
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
:) No problem!
Mark Salsbery Microsoft MVP - Visual C++ :java:
Tydia-kun wrote:
This non-linear way of showing posts in this forum really makes a mess out of things -_-
Yeah, I guess there's a problem with the way MS does the documentation as well, I wonder why the rest of us are ok with all this.... hmmmm maybe we CAN READ! :laugh: This loser could use some Led Zeppelin[^]