一个例子,某位xd写的[DllImport("winmm.dll", EntryPoint="PlaySound")] public static extern int PlaySound ( string lpszName, int hModule, int dwFlags ); int SND_ASYNC = 0x1; int SND_FILENAME = 0x20000; int SND_LOOP = 0x8; PlaySound("sound1.wav",0,SND_ASYNC|SND_FILENAME|SND_LOOP);
public static extern int PlaySound (
string lpszName,
int hModule,
int dwFlags
);
int SND_ASYNC = 0x1;
int SND_FILENAME = 0x20000;
int SND_LOOP = 0x8;
PlaySound("sound1.wav",0,SND_ASYNC|SND_FILENAME|SND_LOOP);
// axWindowsMediaPlayer1
//
this.axWindowsMediaPlayer1.Enabled = true;
this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(160, 224);
this.axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1";
this.axWindowsMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWindowsMediaPlayer1.OcxState")));
this.axWindowsMediaPlayer1.Size = new System.Drawing.Size(0, 0);
this.axWindowsMediaPlayer1.TabIndex = 4;//播放音乐axWindowsMediaPlayer1.URL="type.wav";
private string soundfile;[DllImport("winmm.dll")]
public static extern long PlaySound(String lpszName, long hModule, long dwFlags);
private void PlayASound()
{
if (soundfile != null)
{
PlaySound(Application.StartupPath + "\\" + soundfile, 0, 0);
}
//soundfile = "";
oThread.Abort();
}
private void PlaySoundInThread(string wavefile)
{
soundfile = wavefile;
oThread = new Thread(new ThreadStart(PlayASound));
oThread.Start();
}
private void PlaySound_Click(object sender,System.EventArgs e)
{
PlaySoundInThread(soundfile);
}
添加方法:“工具”菜单选择“添加移除工具箱项",在弹出窗口中选"com组件",在中间选中”windows media player“,就出现在你的工具箱里面了,可以象别的控件一样使用了