title: c++ hooking to a different application, how to find thread id from process id?
body: <p>I would like to add a hook to an application. I am using <code>SetWindowsHookEx</code> and I can create a system wide hook, but I want to create a hook for a particular application. I need to have thread id of the target application to hook it. I know title of the window, I know exe name and from these I can get window handle and process id, but how do I get the thread id? I saw a post about how to do it in <a href="https://stackoverflow.com/questions/1922982/how-can-i-detect-if-a-thread-has-windows-handles">c#</a>, but I do not see how to get a list of threads in c++.</p>
  <pre><code>HWND windowHandle = FindWindow(NULL, _T(&quot;SomeOtherApp&quot;));
  DWORD processId = GetWindowThreadProcessId(windowHandle, NULL);
  DWORD threadId = ??? // How do I get thread id here?
  HHOOK hook = ::SetWindowsHookEx( WH_CBT, HookCBTProc, hInst, threadId);
  </code></pre>
  <p>Thanks,
  Alexander.</p>