33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace VitaliiGanzha.VsDingExtension
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|