close
引用與宣告部分
using System.Runtime.InteropServices;  //命名空間引用 DllImport
-----------------------
// XP 上驗證可行
[DllImport("winmm.dll")]
public static extern long waveOutSetVolume(long deviceID, long Volume);
-------------------------
// 使用Wince 時, 需引用 codedll.dll
[DllImport("coredll.dll", EntryPoint = "waveOutSetVolume")]
extern static Int32 waveOutSetVolume(IntPtr hwo, uint dwVolume);  //設定音量值
[DllImport("coredll.dll", EntryPoint = "waveOutGetVolume")]
private static extern uint waveOutGetVolume(IntPtr device, ref int volume);  //取得音量值
調用方式
//設定音量值
waveOutSetVolume(IntPtr.Zero, 0xFFFF);
//取得音量值
int pdwVolume2;
waveOutGetVolume(IntPtr.Zero, ref pdwVolume2);
MessageBox.Show(pdwVolume2.ToString());
//
waveOutSetVolume(0, 0x0000);
deviceID : Handle to an open waveform-audio output device. This parameter can also be a device identifier. 為0表示預設裝置
Volume : New volume setting. The low-order word contains the left-channel volume setting, and the high-order word contains the right-channel setting. A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.
MSDN:
http://msdn.microsoft.com/en-us/library/ms713762(VS.85).aspx
備註;
//限制音量的取值範圍
if (Value < 0) Value = 0;
if (Value > 0xffff) Value = 0xffff;
System.UInt32 left = (System.UInt32)Value; //左聲道音量
System.UInt32 right = (System.UInt32)Value;//右聲道音量
waveOutSetVolume(0, left << 16 | right);   //邏輯左移後合併

1.DeviceID 可以選擇聲音裝置
2.引用codedll.dll可以支援WinCE



arrow
arrow
    全站熱搜

    神風地球喵 發表在 痞客邦 留言(0) 人氣()