简体   繁体   中英

How do you get Process id of thread?

I wanna get thread id of chrome. I don't want to get the thread id of my window. I want to get the thread id of other windows. What function should i use? and is processor id same as thread id?

You can get the thread id of a window by using the GetWindowThreadProcessId function. It takes two arguments, the first is a handle to the window and the second is the process id. The function returns the thread id. Take a look at here for more info. You can get the handle to a window by using the WindowFromPoint function. (I'm assuming you are on a windows machine).

I think by 'processor', you mean process. process id is not the same as thread id. Every process may have many threads inside each having their own IDs. By sending a parameter to the second argument of the GetWindowThreadProcessId function you can get the process id and it's information.

In the following code win_thread_id would get the thread id of the window that the cursor is on at the time of execution:

HWND handle;
POINT *point = new POINT();
GetCursorPos(point);
handle = WindowFromPoint(*point);

//Get the thread ID for the window from the handle
DWORD win_thread_id;
win_thread_id = GetWindowThreadProcessId(handle, NULL);

NOTE: I didn't test the code, and by the way you should include windows.h

You don't specify the platform in your question. Assuming this is Windows, you can start your research here: http://msdn.microsoft.com/en-us/library/ms684847(v=VS.85).aspx

In short, you'll need to enumerate processes and threads (or alternatively, enumerate windows on the desktop) and then you can open handles to the appropriate resources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM