vsdingextension/VsDingExtensionProject/WinApiHelper.cs
Ernst 9237a8d888 Got a 2017 version of the extension working. Would like to see a single
installer for 2012/2015/2017. So the changes here probably can't be
merged back up, but for standalone installer is fine.
2017-12-01 10:57:20 -08:00

28 lines
980 B
C#

namespace VitaliiGanzha.VsDingExtension
{
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
public static class NativeMethods
{
[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;
}
}
}