屏幕焦点检测源代码

#include <Windows.h> 
#include <wchar.h> 
#include <Psapi.h> 

#pragma comment(lib, "Psapi.lib") 

int main() 
{ 
   HWND last_fore = NULL; 
   wchar_t name[MAX_PATH]; 
   DWORD size = MAX_PATH; 

   while(true) 
   { 
      HWND fore = GetForegroundWindow(); 
      if (fore != last_fore) 
      { 
         last_fore = fore; 

         DWORD processid; 
         GetWindowThreadProcessId(fore, &processid); 

         HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION, NULL, processid); 
         

         GetProcessImageFileNameW(process, name, size); 

         wprintf(L"%s\n", name); 
      } 
      Sleep(10); 
   } 
   return 0; 
}

转的nga某位

posted @ 2016-12-11 17:10  Yosha  阅读(406)  评论(0编辑  收藏  举报