<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 如何:使用平臺調用播放波形文件(C# 編程指南) 下面的 C# 代碼示例演示如何在 Windows 操作系統上使用平臺調用服務來播放波形聲音文件。 此代碼示例使用 **DllImport** 將 **winmm.dll** 的 **PlaySound** 方法入口點作為 Form1 PlaySound() 導入。該示例具有一個帶有一個按鈕的簡單 Windows 窗體。單擊該按鈕可打開標準 Windows [OpenFileDialog](https://msdn.microsoft.com/zh-cn/library/system.windows.forms.openfiledialog.aspx) 對話框,以便打開要播放的文件。選擇波形文件后,將使用 winmm.DLL 程序集方法的 **PlaySound()** 方法來播放此文件。有關 winmm.dll 的 **PlaySound** 方法的更多信息,請參見 [Using the PlaySound function with Waveform-Audio Files](http://go.microsoft.com/fwlink/?LinkId=148553)(使用 PlaySound 函數播放波形音頻文件)。瀏覽并選擇一個帶 .wav 擴展名的文件,然后單擊**“打開”**以使用平臺調用播放該波形文件。將在文本框中顯示選擇的文件的完整路徑。 **“打開文件”**對話框將使用以下篩選器設置只顯示具有 .wav 擴展名的文件: ``` dialog1.Filter = "Wav Files (*.wav)|*.wav"; ``` ``` using System.Windows.Forms; using System.Runtime.InteropServices; namespace WinSound { public partial class Form1 : Form { private TextBox textBox1; private Button button1; public Form1() //constructor { InitializeComponent(); } [System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint = "PlaySound", SetLastError = true, CharSet = CharSet.Unicode, ThrowOnUnmappableChar = true)] private static extern bool PlaySound(string szSound, System.IntPtr hMod, PlaySoundFlags flags); [System.Flags] public enum PlaySoundFlags : int { SND_SYNC = 0x0000, SND_ASYNC = 0x0001, SND_NODEFAULT = 0x0002, SND_LOOP = 0x0008, SND_NOSTOP = 0x0010, SND_NOWAIT = 0x00002000, SND_FILENAME = 0x00020000, SND_RESOURCE = 0x00040004 } private void button1_Click (object sender, System.EventArgs e) { OpenFileDialog dialog1 = new OpenFileDialog(); dialog1.Title = "Browse to find sound file to play"; dialog1.InitialDirectory = @"c:\"; dialog1.Filter = "Wav Files (*.wav)|*.wav"; dialog1.FilterIndex = 2; dialog1.RestoreDirectory = true; if(dialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = dialog1.FileName; PlaySound (dialog1.FileName, new System.IntPtr(), PlaySoundFlags.SND_SYNC); } } } } ``` ## 編譯代碼 ## 編譯代碼 1. 在 Visual Studio 中創建一個新的 C# Windows 應用程序項目,并命名為 WinSound。 2. 復制上面的代碼并將其粘貼到 Form1.cs 文件中以覆蓋原來的內容。 3. 復制下面的代碼,并將它粘貼到 Form1.Designer.cs 文件的 InitializeComponent() 方法中現有代碼的后面。 ``` this.button1 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(192, 40); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(88, 24); this.button1.TabIndex = 0; this.button1.Text = "Browse"; this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(8, 40); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(168, 20); this.textBox1.TabIndex = 1; this.textBox1.Text = "FIle path"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.textBox1); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Platform Invoke WinSound C#"; this.ResumeLayout(false); this.PerformLayout(); ``` 4. 編譯并運行代碼。 ## .NET Framework 安全性 有關更多信息,請參見 [.NET Framework Security](http://go.microsoft.com/fwlink/?LinkId=37122)(.NET Framework 安全性)。 ## 請參閱 [C# 編程指南](https://msdn.microsoft.com/zh-cn/library/67ef8sbd.aspx) [互操作性概述(C# 編程指南)](https://msdn.microsoft.com/zh-cn/library/ms173185.aspx) [互操作性概述(C# 編程指南)](https://msdn.microsoft.com/zh-cn/library/ms173185.aspx) [A Closer Look at Platform Invoke](https://msdn.microsoft.com/zh-cn/library/0h9e9t7d.aspx) [用平臺調用封送數據](https://msdn.microsoft.com/zh-cn/library/fzhhdwae.aspx)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看