using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//引用新的命名空间,以调用windows系统自带的PlaySound函数
namespace PlaySound
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//读者只需要知道使用这种方法使用PlaySound()就可以!
//播放响应用户操作的声音和背景音乐,前者使用Windows系统自带的播放声音的函数PlaySound,而背景音乐的播放则使用Windows Media Play控件
public DllImport
[DllImport("winmm")]
public static extern bool PlaySound(string szSound,int hMod,int i);
private void Play(string waveName)
{
PlaySound(Application.StartupPath +"\\"+waveName,0,1);
}
private void PlayMusic(string musicName)
{
this.axWindowsMediaPlayer1.URL ="";
this.axWindowsMediaPlayer1.URL =Application.StartupPath+"\\"+musicName;
}
private void Button1_Click(object sender, EventArgs e)
{
this.Play("Shot.wav");
}
private void Button2_Click(object sender, EventArgs e)
{
this.PlayMusic("town.mid");
}
}
}
错误 “PlaySound.DllImportAttribute”不包含采用“1”个参数的构造函数