已经知道进程名和进程id,如何取线程id

解决方案 »

  1.   

    先用OpenProcess由ProcessID得到ProcessHANDLE
    再由GetWindowThreadProcessId得到线程id
      

  2.   

    2楼你搞错了
    GetWindowThreadProcessId 是通过窗口句柄返回进程ID的指针和线程ID
      

  3.   

    不好意思,是我错的
    但你可以通过EnumWindows得到所有窗口的名柄,然后用GetWindowThreadProcessId得到进程ID和线程ID
    然后判进程ID与你已知的进程id,得到你要的线程ID
      

  4.   

    另一方法:
    用Thread32First+Thread32Next
      var
      xxx:THREADENTRY32;
    ...
      if xxx.th32OwnerProcessID =你的进程id then
      xxx.th32ThreadID 就是该进程的线程ID(当然有多个,要在Thread32Next循环中)
      

  5.   

    Tlhelp32 // Tool Help FunctionsTHREADENTRY32 // 线程列表入口,从该结构里就能得到线程ID(th32ThreadID)CreateToolhelp32Snapshot // 创建线程列表快照Thread32First // 开始遍历Thread32Next // 继续遍历