vsdingextension/VsDingExtensionProject/WinApiHelper.cs

29 lines
979 B
C#
Raw Normal View History

namespace VitaliiGanzha.VsDingExtension
{
2016-01-06 03:31:37 +00:00
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
public static class WinApiHelper
{
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);
public static 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;
}
}
}