⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dshandler.cs

📁 这是网上下载的很好的串口发短信的程序! 是用VC++来做的
💻 CS
字号:
using System;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
using Buffer = Microsoft.DirectX.DirectSound.SecondaryBuffer;

namespace DDGameHelper
{
	/// <summary>
	/// DSHandler 现在还有问题。须向 DDHandler 一样,为每种声音建立 SecondBuffer 并播放,而非重复载入
	/// </summary>
	public class DSHandler
	{
		private SecondaryBuffer ApplicationBuffer = null;
		private Device ApplicationDevice = null;
		private string PathSoundFile = string.Empty;
		private Form _ownerForm;

		public DSHandler(Form ownerForm)
		{
			_ownerForm=ownerForm;
		}

		public bool Init(ref string msg)
		{
			ApplicationDevice = new Device();
			try
			{
				ApplicationDevice.SetCooperativeLevel(_ownerForm, CooperativeLevel.Priority);
			}
			catch
			{
				return false;
			}
			return true;
		}
		public void Stop()
		{
			if(null != ApplicationBuffer)
				ApplicationBuffer.Stop();
		}

		public void Play()
		{
			if(null != ApplicationBuffer)
				ApplicationBuffer.Play(0, BufferPlayFlags.Default);
		}

		public bool LoadSoundFile(string name)
		{
			try
			{
				ApplicationBuffer = new SecondaryBuffer(name, ApplicationDevice);
			}
			catch(SoundException)
			{
				return false;
			}
			return true;
		}
		public bool LoadSoundFile(System.IO.Stream s)
		{
			try
			{
				ApplicationBuffer = new SecondaryBuffer(s, ApplicationDevice);
			}
			catch(SoundException)
			{
				return false;
			}
			return true;
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -