我想捕获窗口活动窗口更改事件。假设用户正在使用VS并切换到IE,我想要捕获此活动窗口更改事件。我在互联网上搜索,发现很多例子,但似乎没有任何工作对我来说。捕获活动窗口更改事件中的问题
这是我写到目前为止的代码,我不确定这是什么问题。我无法通过此
class Program
{
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);
private const uint WINEVENT_OUTOFCONTEXT = 0;
private const uint EVENT_SYSTEM_FOREGROUND = 3;
static void Main(string[] args)
{
WinEventDelegate dele = new WinEventDelegate(WinEventProc);
IntPtr m_hhook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, dele, 0, 0, WINEVENT_OUTOFCONTEXT);
Console.ReadKey();
}
static void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
Console.WriteLine("Something");
}
}
WinEventProc
不会被调用来捕获所需的事件,有谁能够确定什么,我编程或概念做错了什么?我正在使用Windows 7
一个很不错的,工作的解决方案是在这里:http://stackoverflow.com/a/11943387/134761 – angularsen