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.IO;
using System.Media; using System.Media;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms;
using EnvDTE; using EnvDTE;
using EnvDTE80; using EnvDTE80;
using Microsoft.VisualStudio.ComponentModelHost; using Microsoft.VisualStudio.ComponentModelHost;
@ -95,15 +96,14 @@ namespace VitaliiGanzha.VsDingExtension
{ {
if (onlyOnUnFocus && !ApplicationIsActivated()) if (onlyOnUnFocus && !ApplicationIsActivated())
{ {
return; try
} {
try soundPlayer.Play();
{ }
soundPlayer.Play(); catch (Exception ex)
} {
catch (Exception ex) ActivityLog.LogError(GetType().FullName, ex.Message);
{ }
ActivityLog.LogError(GetType().FullName, ex.Message);
} }
} }
@ -125,19 +125,18 @@ namespace VitaliiGanzha.VsDingExtension
Debug.WriteLine(string.Format("OnlyOnUnFocus: {0}", onlyOnUnFocus)); Debug.WriteLine(string.Format("OnlyOnUnFocus: {0}", onlyOnUnFocus));
} }
public static bool ApplicationIsActivated()
public bool ApplicationIsActivated()
{ {
var activatedHandle = GetForegroundWindow(); var activatedHandle = GetForegroundWindow();
if (activatedHandle == IntPtr.Zero) if (activatedHandle == IntPtr.Zero)
{ {
return false; // No window is currently activated return false; // No window is currently activated
} }
var procId = Process.GetCurrentProcess().Id; var procId = Process.GetCurrentProcess().Id;
int activeProcId; int activeProcId;
GetWindowThreadProcessId(activatedHandle, out activeProcId); GetWindowThreadProcessId(activatedHandle, out activeProcId);
return activeProcId == procId;
return activeProcId == procId;
} }
} }