Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need threadid from processid in WinNT/2000

Status
Not open for further replies.

btrswt

Programmer
Feb 4, 2003
2
US
I have an application that I use to request applications to shutdown. I iterate through the running processes, get the name of the executable and compare it against the list of executables that need to be shutdown. If I find it on the list, I want to post a message to its main message loop.

The old (ok ancient) windows API call was [tt]PostAppMessage[/tt] that took a task handle. MSDN lists this function as an 'Obsolete Windows Programming Element' and lists [tt]PostThreadMessage[/tt] as the replacement. [tt]PostThreadMessage[/tt] requires a threadid.

I was previously enumerating the system windows, looking for one that matched and posting the message to the window, but the applications no-longer have a 'main' window that I can uniquely identify.

I'm also open to other ideas if you have any.

 
Hi :)

How about using GetWindowThreadProcessId to get the ThreadID? you can then pass it along to PostThreadMessage.



 
Thanks for the idea, it got me where I needed to be. [thumbsup2]

I ended up going back to EnumWindows to go through the windows in the system. For each window I used GetWindowThreadProcessId to get the associated thread id and process id. I used the process id with psapi.h calls to determine the program associated with the window. If it was on the list, I used the thread id with PostThreadMessage.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top