我需要这个句柄来调用WaitForSingleObject,大家帮帮忙。

解决方案 »

  1.   

    555,不行啊,没这个函数,这是知识库里的文章说的
    There is no way to get the thread handle from the thread ID. While there is an OpenProcess() API that takes a PID and returns the handle to the process, there is no corresponding OpenThread() that takes a thread ID and returns a thread handle. 
      

  2.   

    有啊,看msdn
    HANDLE OpenThread(
      DWORD dwDesiredAccess,  // access right
      BOOL bInheritHandle,    // handle inheritance option
      DWORD dwThreadId        // thread identifier
    );
    你是怎么创建线程的?如果是afxbeginthread
    那么cwinthread就有m_hThread这个成员啊,它就
    是个handle
      

  3.   

    哦,看到了,要新的MSDN才有,可是不能用啊,用了以后我的程序只能在2000跟ME下用了。。
    Requirements 
      Windows NT/2000/XP: Included in Windows 2000 and later.
      Windows 95/98/Me: Included in Windows Me.
      Header: Declared in Winbase.h; include Windows.h.
      Library: Use Kernel32.lib.我是用CreateProcess新建进程打开一个文件的,可是很多程序如果系统里已经有一个进程,新开的进程就会马上结束,原来的进程会新开一个线程来打开这个文件,我就想要得到这个线程的句柄。我现在是枚举窗口,找到打开我的文件的窗口以后调用GetWindowThreadProcessId来得到线程的Id,可是我必须要有线程的句柄才能用来调用WaitForSingleObject..
      

  4.   

    那你可以用这个函数得到句柄啊
    HANDLE GetCurrentThread(VOID);