public override void ActivateForm(Window form, Window window, IntPtr hwnd) {
var fHandle = (PresentationSource.FromVisual(form) as HwndSource).Handle;
var wHandle = (PresentationSource.FromVisual(window) as HwndSource).Handle;
if (window == null || wHandle != fHandle) {
uint fgProcessId;
uint spProcessId;
User32.GetWindowThreadProcessId(User32.GetForegroundWindow(), out fgProcessId);
User32.GetWindowThreadProcessId(fHandle, out spProcessId);
if (fgProcessId != spProcessId) {
if (User32.AttachThreadInput(fgProcessId, spProcessId, true)) {
User32.SetForegroundWindow(fHandle);
User32.AttachThreadInput(fgProcessId, spProcessId, false);
}
} else {
User32.SetForegroundWindow(fHandle);
}
// stop flashing...happens occassionally when switching quickly when activate manuver is fails
Shell32.FlashWindow(fHandle, 0);
}
}
}