Fixed unfocus check

This commit is contained in:
Dan Forsyth 2015-06-04 14:42:54 -04:00
parent cc3ae003ce
commit 99d95138ab
1 changed files with 12 additions and 13 deletions

View File

@ -4,6 +4,7 @@ using System.Globalization;
using System.IO;
using System.Media;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.ComponentModelHost;
@ -95,8 +96,6 @@ namespace VitaliiGanzha.VsDingExtension
{
if (onlyOnUnFocus && !ApplicationIsActivated())
{
return;
}
try
{
soundPlayer.Play();
@ -106,6 +105,7 @@ namespace VitaliiGanzha.VsDingExtension
ActivityLog.LogError(GetType().FullName, ex.Message);
}
}
}
private void OperationStateOnStateChanged(object sender, OperationStateChangedEventArgs operationStateChangedEventArgs)
{
@ -125,18 +125,17 @@ namespace VitaliiGanzha.VsDingExtension
Debug.WriteLine(string.Format("OnlyOnUnFocus: {0}", onlyOnUnFocus));
}
public static bool ApplicationIsActivated()
public bool ApplicationIsActivated()
{
var activatedHandle = GetForegroundWindow();
if (activatedHandle == IntPtr.Zero)
{
return false; // No window is currently activated
}
var procId = Process.GetCurrentProcess().Id;
int activeProcId;
GetWindowThreadProcessId(activatedHandle, out activeProcId);
return activeProcId == procId;
}