|
The GetWindowThreadProcessId() API can help.
This came up recently here and I can't remember how to get the name from the process ID.
I think you need to enumerate the processes on the system and find the one that matches the ID.
A couple ways to enumerate processes:
CreateToolhelp32Snapshot()/Process32First()/Process32Next()
Use WMI and the Win32_Process class
Tydia-kun wrote: It should be possible as it's the very same thing Task Manager does.
I'm not sure why task manager would use window handles to find processes when there's many
methods available for enumerating processes and task manager also shows processes that don't
have any windows. I'd guess that task manager uses WMI.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
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++
|
|
|
|
|
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++
|
|
|
|
|
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!
|
|
|
|
|
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++
|
|
|
|
|
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++
|
|
|
|
|
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++
|
|
|
|
|
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++
|
|
|
|
|
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++
|
|
|
|
|
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!
This loser could use some Led Zeppelin[^]
|
|
|
|
|
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++
|
|
|
|
|
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++
|
|
|
|
|
Is there a way to convert a unicode string as the user would type it into an array of unicode characters as they would be displayed?
For example, typing unicode character 0x0628 followed by 0x0627 will actually display as unicode character 0xfe91 followed by 0xfe8e.
Thanks
...Matt
|
|
|
|
|
The simple answer is yes. Have I done it? No! If you want to translate a series of values (combined values – in Unicode) to a character with a specific value (which Unicode usually supplies), then you are dealing with a display representation of the character and it is up to the designer of the font display code to decide how to do it. Unfortunately most programmers who are privy to that information are under contract not to tell.
If you need to just do a translation from combined values to a different Unicode value, then you are probably on you own; although I have the impression that they do what you are trying to do. It should not be too difficult, the character listings are online and the official information is available for purchase.
Good Luck!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Is there a way I can search a directory and read a file name and date created in C++??
|
|
|
|
|
FindFirstFile /FindFirstFileEx and friends
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
I am curious, what development environment are you using? That is basic information that was available to programmers before the advent of Windows (or other modern OSs).
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
|
Please sharing open source of a software(If it is written by C++ ,which is very wonderful) .This software can manage one Netroom.User can shutdown,restart and end process which is running on client throught server.If you have it,you can send me throught email adress:vanthang140986@yahoo.com.Thank you very much
hhhhhhhhhhhhhhhhh
|
|
|
|