using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace soundfile
{
///
/// Summary description for Form1.
///
public class WAVSounds : System.Windows.Forms.Form
{
//[DllImport("WinMM.dll")]
public static extern bool PlaySound(byte[]wfname, int fuSound);
public int SND_ASYNC = 0x0001; // play asynchronously
private System.Windows.Forms.TextBox m_wav_file;
private System.Windows.Forms.Button PlayButton;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
~WAVSounds()
{
}
public WAVSounds()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
public void Play(string wfname,int SoundFlags)
{
byte[] bname = new Byte[256]; //Max path length
bname = System.Text.Encoding.ASCII.GetBytes(wfname);
PlaySound(bname,SoundFlags);
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.m_wav_file = new System.Windows.Forms.TextBox();
this.PlayButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// m_wav_file
//
this.m_wav_file.Location = new System.Drawing.Point(16, 144);
this.m_wav_file.Name = "m_wav_file";
this.m_wav_file.Size = new System.Drawing.Size(512, 20);
this.m_wav_file.TabIndex = 0;
this.m_wav_file.Text = "";
this.m_wav_file.Visible = false;
//
// PlayButton
//
this.PlayButton.Location = new System.Drawing.Point(120, 40);
this.PlayButton.Name = "PlayButton";
this.PlayButton.Size = new System.Drawing.Size(200, 40);
this.PlayButton.TabIndex = 1;
this.PlayButton.Text = "PlayButton";
//
// WAVSounds
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(544, 266);
this.Controls.Add(this.PlayButton);
this.Controls.Add(this.m_wav_file);
this.Name = "WAVSounds";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new WAVSounds());
}
private void OnPlayButtonClick(object sender, System.EventArgs e)
{
WAVSounds ws = new WAVSounds();
ws.Play(m_wav_file.Text,ws.SND_ASYNC);
}
}
}