- UID
- 25837
注册时间2006-10-5
阅读权限20
最后登录1970-1-1
以武会友
该用户从未签到
|
主要代码如下:
//api定义
private const int SND_MEMORY = 0x4;
[DllImport("winmm.dll")]
private static extern int sndPlaySoundA(byte[] lpszSoundName, int uFlags);
private void Form1_Load(object sender, EventArgs e)
{
Thread MyThread = new Thread(new ThreadStart(MyThread1));\\开启新线程不影响主程序
MyThread.Start();
}
private void MyThread1()
{
Type t = this.GetType();
System.Reflection.Assembly a = t.Assembly;
System.IO.Stream stream = a.GetManifestResourceStream("WindowsApplication1.Resources.sound.wav");
//wav音效加入到嵌入资源文件夹并且生成操作为嵌入的资源
byte[] ba = new byte[stream.Length];
stream.Read(ba, 0, ba.Length);
stream.Close();
//播放
sndPlaySoundA(ba, SND_MEMORY);
Application.Exit();
}
播放结束自动退出,选了个歌曲有点长。。。嘿嘿。 |
评分
-
查看全部评分
|