1. 程式人生 > >Win32判斷當前程序是否啟用(失去焦點)

Win32判斷當前程序是否啟用(失去焦點)

DWORD GetCurrentActiveWindowsProcessId()  
{  
  HWND hWnd = GetActiveWindow();  
  DWORD processId = 0;  
  GetWindowThreadProcessId(hWnd, &processId);  
  return processId;  
}  

BOOL HasFocus() {
  DWORD active_process = GetCurrentActiveWindowsProcessId();
  DWORD current_process = ::GetCurrentProcessId();
  return current_process ==  active_process ;
}