如何在程式中調用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);
效果:
完整樣本在這裡下載:
http://files.cnblogs.com/fox23/ControlPanelSample.rar
Enjoy!
相關資料:
Show Control Panel Programmatically
http://www.pocketpcdn.com/articles/controlpanel.html