This is similar to
an alternative SO question , I would suggest that you simply track the active window and after the change you will find out the previously active
, , , , , , , , lastHandle , lastHandle. , :
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
static IntPtr lastHandle = IntPtr.Zero;
IntPtr GetLastActive()
{
IntPtr curHandle = GetForeGroundWindow();
IntPtr retHandle = IntPtr.Zero;
if(curHandle != lastHandle)
{
retHandle = lastHandle;
lastHandle = curHandle;
if(retHandle != IntPtr.Zero)
return retHandle;
}
}