using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Runtime.InteropServices; namespace WavPlayTest { /// /// Summary description for Form1. /// public class WAVSounds { [DllImport("WinMM.dll")] public static extern bool PlaySound(byte[]wfname, int fuSound); // flag values for SoundFlags argument on PlaySound public int SND_SYNC = 0x0000; // play synchronously (default) public int SND_ASYNC = 0x0001; // play asynchronously //-------------------------------------------------------------------- public WAVSounds() { } //------------------------------------------------------------------- ~WAVSounds() { } //------------------------------------------------------------------- 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); } //-------------------------------------------------------------------- } //End WAVSounds class //---------------------------------------------------------------------- public class Form1 : System.Windows.Forms.Form { [DllImport("user32.dll")] public static extern int MessageBox(int hWnd, String text, String caption, uint type); private System.Windows.Forms.TextBox m_wav_file; private System.Windows.Forms.Button PlayButton; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// 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(95, 68); this.m_wav_file.Name = "m_wav_file"; this.m_wav_file.Size = new System.Drawing.Size(256, 20); this.m_wav_file.TabIndex = 2; this.m_wav_file.Text = "C:\\Documents and Settings\\Ayah\\Desktop\\engine.wav"; this.m_wav_file.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.m_wav_file.Visible=false; // // PlayButton // this.PlayButton.Location = new System.Drawing.Point(387, 70); this.PlayButton.Name = "PlayButton"; this.PlayButton.Size = new System.Drawing.Size(69, 22); this.PlayButton.TabIndex = 4; this.PlayButton.Text = "Play"; this.PlayButton.Click += new System.EventHandler(this.OnPlayButtonClick); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(520, 218); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.PlayButton, this.m_wav_file, }); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } //------------------------------------------------------------------------ private void OnPlayButtonClick(object sender, System.EventArgs e) { WAVSounds ws = new WAVSounds(); ws.Play(m_wav_file.Text,ws.SND_ASYNC); } //------------------------------------------------------------------------- } //end class } //end name space