调用Windows Mobile自带的控制面板项(转)
如何在程序中调用Windows Mobile系统自带的控制面板项呢?经常在论坛或者邮件组看到这样的问题, 比如我们也许在自己的程序中需要添加一个“移除程序”功能,或者需要用户设置一下闹钟,或者需要修改一下其他的系统设置,这时候也许直接调用系统自带的控制面板,要比自己修改注册表自己设计消息存储方式自己设计UI要简单的多。
下面这个类就实现了这一功能:
class ControlApplet { public static void ShowApplet(AppletType applet) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = @"\Windows\ctlpnl.exe"; startInfo.Arguments = String.Format("cplmain.cpl,{0}", (byte)applet); Process.Start(startInfo); } public static void ShowApplet(AppletType applet, byte tabIndex) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = @"\Windows\ctlpnl.exe"; startInfo.Arguments = String.Format("cplmain.cpl,{0},{1}", (byte)applet, tabIndex); Process.Start(startInfo); } public enum AppletType { Contrast, Password, OwnerInformation, Power, Memory, About, Backlight, AlignScreen, InputMethod, SoundsReminders, RemovePrograms, Menus, Buttons, TodaySettings, PCConnections, ModemConnections, Clock, NetworkConnections, RegionalSettings } #region Constant Fields public const byte CPAPPLET_OWNERINFO_IDENTIFICATION = 0; public const byte CPAPPLET_OWNERINFO_NOTES = 1; public const byte CPAPPLET_MEMORY_MAIN = 0; public const byte CPAPPLET_MEMORY_RUNNINGPROGRAMS = 1; public const byte CPAPPLET_ABOUT_VERSION = 0; public const byte CPAPPLET_ABOUT_DEVICEID = 1; public const byte CPAPPLET_ABOUT_COPYRIGHTS = 2; public const byte CPAPPLET_BACKLIGHT_BATTERY = 0; public const byte CPAPPLET_BACKLIGHT_EXTERNAL = 1; public const byte CPAPPLET_INPUT_INPUTMEHTOD = 0; public const byte CPAPPLET_INPUT_WORDCOMPLETION = 1; public const byte CPAPPLET_INPUT_OPTIONS = 2; public const byte CPAPPLET_SNDANDREMINDERS_VOLUME = 0; public const byte CPAPPLET_SNDANDREMINDERS_SOUNDS = 1; public const byte CPAPPLET_SNDANDREMINDERS_REMINDERS = 2; public const byte CPAPPLET_MENUS_STARTMENU = 0; public const byte CPAPPLET_MENUS_NEWMENU = 1; public const byte CPAPPLET_BUTTONS_PROGRAMBUTTONS = 0; public const byte CPAPPLET_BUTTONS_UPDOWNCONTROL = 1; public const byte CPAPPLET_MODEM_CONNECTIONS = 0; public const byte CPAPPLET_MODEM_DIALING = 1; public const byte CPAPPLET_CLOCK_TIME = 0; public const byte CPAPPLET_CLOCK_ALARMS = 1; public const byte CPAPPLET_RS_REGION = 0; public const byte CPAPPLET_RS_NUMBER = 1; public const byte CPAPPLET_RS_CURRENCY = 2; public const byte CPAPPLET_RS_TIME = 3; public const byte CPAPPLET_RS_DATE = 4; #endregion }简单来说就是启动ctlpnl.exe,并传入相应的参数即可,注意第一个参数是表示控制台的哪一项,第二个参数(如果有的话)是表示控制台项目的具体哪个标签页,它为空时默认为第一个标签页。使用的时候如下:
ControlApplet.ShowApplet(ControlApplet.AppletType.Clock);
效果:
ControlApplet.ShowApplet(ControlApplet.AppletType.Clock, ControlApplet.CPAPPLET_CLOCK_ALARMS);
效果:
完整示例在这里下载:
https://files.cnblogs.com/fox23/ControlPanelSample.rar
Enjoy!
相关资料: