开发者

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开发者_StackOverflow thread id?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜