最近一個Mobile項目中需要通過代碼開啓點擊屏幕輸出聲音的功能.首先驗證了一下在手邊各種類型的Mobile設備在系統設置頁面都有設置點擊屏幕是否發聲的選項.經驗證這是一個Windows Mobile的通用選項,那能通過代碼控制這個選項麼? 答案是肯定的,而且僅僅需要幾行代碼.
[DllImport("Coredll.dll")]
private static extern void AudioUpdateFromRegistry();
static readonly string KeyVolRegKey = @"HKEY_CURRENT_USER\ControlPanel\Volume";
public KeyClickVolume KeyClickVolume
{
set
{
uint[] vals = new uint[] { 0, 1, 0x10002 };
Registry.SetValue(KeyVolRegKey, "Screen", vals[(int)value], RegistryValueKind.DWord);
AudioUpdateFromRegistry();
EventLog(ErrorLevel.Info, String.Empty,string.Format( "Set KeyClickVolume to {0}",value), null);
}
get
{
switch ((uint)Registry.GetValue(KeyVolRegKey, "Screen", (uint)0x10002))
{
case 0: return KeyClickVolume.Off;
case 1: return KeyClickVolume.Soft;
case 0x10002:
default: return KeyClickVolume.Loud;
}
}
}
KeyClickVolume的定義如下:
public enum KeyClickVolume
{
Off = 0,
Soft,
Loud
};
另外除了可以設置點擊Screen的聲音外,你還可以對類似的其它選項進行設置.具體的鍵值可以參照下圖:
參考:
http://stackoverflow.com/questions/982934/how-do-you-disable-the-key-click-sound-in-windows-ce
http://go4answers.webhost4life.com/Example/set-phone-volume-please-help-why-55820.aspx