void _client_MouseClick(object sender, MouseEventArgs e) { var handle = NativeMethods.ChildWindowFromPoint(_client.Handle, e.Location); if (handle == IntPtr.Zero || handle == _client.Handle) return; // Find the child that was clicked. System.Windows.Forms.Form clickedForm = null; foreach (var form in Parent.MdiChildren) { if (form.Handle == handle) { clickedForm = form; break; } } if (clickedForm == null) return; // Activate the correct form. var topForm = FindTopForm(clickedForm); if (topForm.ContainsFocus) { StopFlashing(); var info = new NativeMethods.FLASHWINFO(); info.cbSize = (uint)Marshal.SizeOf(info); info.hWnd = topForm.Handle; info.dwFlags = NativeMethods.FLASHW_TIMER | NativeMethods.FLASHW_ALL; NativeMethods.FlashWindowEx(ref info); _flashingForm = topForm; _flashTimer.Start(); } else { topForm.Focus(); } }
private void StopFlashing() { _flashTimer.Stop(); if (_flashingForm != null) { var info = new NativeMethods.FLASHWINFO(); info.cbSize = (uint)Marshal.SizeOf(info); info.hWnd = _flashingForm.Handle; info.dwFlags = NativeMethods.FLASHW_STOP; NativeMethods.FlashWindowEx(ref info); if (_flashingForm.ContainsFocus) { NativeMethods.SetWindowPos( _flashingForm.Handle, IntPtr.Zero, 0, 0, 0, 0, NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOMOVE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_FRAMECHANGED ); } _flashingForm = null; } }