当需要报警时,就弹出对话框,并像QQ一样不停地闪存,并且发出报警声 C#
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")] public static extern bool FlashWindow(IntPtr handle, bool bInvert); private void timer1_Tick(object sender, EventArgs e) { try { FlashWindow(this.Handle, true); if (enableAlarm && alarmCount>0) { string path = System.Windows.Forms.Application.StartupPath + @"/Resources/ALARM8.WAV"; MediaSound.PlaySound(path, true, true, false); this.alarmCount--; } } catch (Exception ex) { AirMonitorSysEventLog.WriteLog("FormAlarm--timer1_Tick: " + ex.Message, System.Diagnostics.EventLogEntryType.Error, AirMonitorSysEventLog.GeneralErrorEventId); } }
注意,这个Timer 's interval is 100 ms,
public class MediaSound { #region 报警声音 /* 当例如监测xx大于xx * 通过PlaySound(”msg.wav”, true, true, false)方法实现连续报警 * 还可以同时弹出窗口提醒之类的信息. * 关闭报警通过方法StopSound()实现就可以了.*/ [DllImport("winmm.dll", EntryPoint = "PlaySound")] private static extern bool Win32_PlaySound(string pszSound, IntPtr hmod, uint fdwSound); /// <summary> /// 播放一个wav音频文件 /// </summary> /// <param name="path"></param> /// <param name="asynchronous"></param> /// <param name="loop"></param> /// <param name="doNotStopPlay"></param> public static void PlaySound(string path, bool asynchronous, bool loop, bool doNotStopPlay) { Win32_PlaySound(path, IntPtr.Zero, (uint)((asynchronous ? PlaySoundMessage.SND_ASYNC : PlaySoundMessage.SND_SYNC) | (loop ? PlaySoundMessage.SND_LOOP : 0) | (doNotStopPlay ? PlaySoundMessage.SND_NOSTOP : 0) | PlaySoundMessage.SND_FILENAME)); } /// <summary> /// 停止播放 /// </summary> public static void StopSound() { Win32_PlaySound(null, IntPtr.Zero, 0); } [Flags()] internal enum PlaySoundMessage { SND_SYNC = 0x0000, SND_ASYNC = 0x0001, SND_LOOP = 0x0008, SND_NOSTOP = 0x0010, SND_FILENAME = 0x00020000 } #endregion }