最近一个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