35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Runtime.InteropServices;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace FocusVolumeControl
|
|||
|
{
|
|||
|
internal class Native
|
|||
|
{
|
|||
|
internal delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
|
|||
|
|
|||
|
[DllImport("user32.dll")]
|
|||
|
static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);
|
|||
|
|
|||
|
[DllImport("user32.dll")]
|
|||
|
internal static extern bool UnhookWinEvent(IntPtr hWinEventHook);
|
|||
|
|
|||
|
|
|||
|
private const uint WINEVENT_OUTOFCONTEXT = 0;
|
|||
|
private const uint EVENT_SYSTEM_FOREGROUND = 3;
|
|||
|
|
|||
|
internal static IntPtr RegisterForForegroundWindowChangedEvent(WinEventDelegate dele) => SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, dele, 0, 0, WINEVENT_OUTOFCONTEXT);
|
|||
|
|
|||
|
|
|||
|
[DllImport("user32.dll")]
|
|||
|
internal static extern IntPtr GetForegroundWindow();
|
|||
|
|
|||
|
[DllImport("user32.dll", SetLastError = true)]
|
|||
|
internal static extern uint GetWindowThreadProcessId(IntPtr hWnd, out int processId);
|
|||
|
|
|||
|
}
|
|||
|
}
|