枚举系统所有进程和进程所有线程(比如:获得线程窗口)

类别:VC语言 点击:0 评论:0 推荐:

 HANDLE m_hProcessSnap = NULL;
 HANDLE m_hThreadSnap = NULL;
 HANDLE m_hProcess = NULL;
 HANDLE m_hThread = NULL;
 PROCESSENTRY32 m_pe32;
 THREADENTRY32 m_te32;
 memset(&m_pe32,0,sizeof(m_pe32));
 m_pe32.dwSize = sizeof(PROCESSENTRY32);
 memset(&m_te32,0,sizeof(m_te32));
 m_te32.dwSize = sizeof(THREADENTRY32);
 m_hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
 m_hThreadSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
 WNDENUMPROC lpFun = EnumThreadWndProc;
 BOOL IsHas = FALSE;
 if (::Process32First(m_hProcessSnap,&m_pe32))
 {
  do
  {
   m_hProcess = ::OpenProcess(PROCESS_ALL_ACCESS,FALSE,m_pe32.th32ProcessID);
   
   if (::Thread32First(m_hThreadSnap,&m_te32))
   {
    do
    {
     
     if (m_pe32.th32ProcessID == m_te32.th32OwnerProcessID)
     {
      ::EnumThreadWndProc(m_te32.th32ThreadID,
       lpFun,
       0);/*枚举所有线程窗口HWND*/
     }
     
    }
    while (::Thread32Next(m_hThreadSnap,&m_te32));
   }
   
  }
  while (::Process32Next(m_hProcessSnap,&m_pe32));
 }

本文地址:http://com.8s8s.com/it/it315.htm