?? mainform.cs
字號:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace PlayingSound
{
public partial class MainForm : Form
{
private const UInt32 SND_SYNC = 0x00000000;
private const UInt32 SND_ASYNC = 0x00000001;
private const UInt32 SND_NODEFAULT = 0x00000002;
private const UInt32 SND_MEMORY = 0x00000004;
private const UInt32 SND_LOOP = 0x00000008;
private const UInt32 SND_NOSTOP = 0x00000010;
private const UInt32 SND_NOWAIT = 0x00002000;
private const UInt32 SND_ALIAS = 0x00010000;
private const UInt32 SND_FILENAME = 0x00020000;
private const UInt32 SND_RESOURCE = 0x00040004;
public MainForm()
{
InitializeComponent();
}
[DllImport("coredll.dll",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode,
EntryPoint = "PlaySound",
PreserveSig = true,
SetLastError = false)]
private extern static bool PlaySound(
String pszSound,
IntPtr hmod,
UInt32 fdwSound);
private void m_btnBrowse_Click(object sender, EventArgs e)
{
if(DialogResult.OK != m_openFileDialog.ShowDialog())
return;
m_txtFile.Text = m_openFileDialog.FileName;
}
// “Play Once”按鈕
private void m_btnPlayOnce_Click(object sender, EventArgs e)
{
// 播放指定的文件一次
PlaySound(m_txtFile.Text, IntPtr.Zero, SND_ASYNC | SND_FILENAME);
}
// “Play Loop”按鈕
private void m_btnPlayLoop_Click(object sender, EventArgs e)
{
// 循環(huán)播放指定的文件
PlaySound(m_txtFile.Text, IntPtr.Zero, SND_ASYNC | SND_FILENAME | SND_LOOP);
}
// “Stop”按鈕
private void m_btnStop_Click(object sender, EventArgs e)
{
// 將第一個(gè)參數(shù)設(shè)置為null可以終止聲音的播放
PlaySound(null, IntPtr.Zero, SND_ASYNC | SND_FILENAME);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -