public static extern int FlashWindowEx(ref FlashInfo pfwi);
/// <summary> /// Will check that the first instance flag is false /// and if true it will try to flash the window of the already /// running trace app. /// </summary> /// <param name="firstInstance"></param> /// <returns></returns> static bool IsRunning(bool firstInstance) { if (!firstInstance) { System.Diagnostics.Trace.WriteLine("Detected we are already running in another instance!", "Detect Startup"); Process[] processes = Process.GetProcessesByName("Workshare.Trace"); foreach (Process process in processes) { if (process.MainWindowHandle != IntPtr.Zero) { System.Diagnostics.Trace.WriteLine("Detected the process window. Trying to bring to front!", "Detect Startup"); SetForegroundWindow(process.MainWindowHandle); FlashInfo flashArgs = new FlashInfo(); flashArgs.Timeout = 0; flashArgs.WindowHandle = process.MainWindowHandle; flashArgs.Size = Convert.ToUInt32(Marshal.SizeOf(typeof(FlashInfo))); flashArgs.Flags = (Int32)(NativeMethods.FlashInfoFlags.FlashAll | NativeMethods.FlashInfoFlags.FlashTimerContinues); NativeMethods.FlashWindowEx(ref flashArgs); break; } } return true; } return false; }
private void ReportProcessCompleteToUser(object unused) { if (m_startup.Settings.IsRunningTest) return; if (string.Compare(m_startup.Settings.Language, "default", true, Thread.CurrentThread.CurrentCulture) != 0) { System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(m_startup.Settings.Language, true); Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; } if (InvokeRequired) { Invoke(new ObjectParamDelegate(ReportProcessCompleteToUser), new object[] { null }); } else { //const MessageBoxOptions options = 0; if (WindowState == FormWindowState.Minimized || Visible == false) { FlashInfo flashArgs = new FlashInfo { Timeout = 0, WindowHandle = Handle, Size = Convert.ToUInt32(Marshal.SizeOf(typeof(FlashInfo))), Flags = (Int32)(NativeMethods.FlashInfoFlags.FlashAll | NativeMethods.FlashInfoFlags.FlashTimerContinues) }; NativeMethods.FlashWindowEx(ref flashArgs); //Have not message boxed the user yet. This is deferred until the screen in not minimized m_pendingNotification = true; } else { GC.Collect(); //MessageBox.Show(this, Properties.Resources.SCANCOMPLETED, // Properties.Resources.STARTSCAN_BALLOON_TITLE, // MessageBoxButtons.OK, // MessageBoxIcon.Information, // MessageBoxDefaultButton.Button1, // options); // Update the button states ButScan.Enabled = true; } } }