如何在程式中調用Windows Mobile系統自帶的控制台項呢?經常在論壇或者郵件組看到這樣的問題, 比如我們也許在自己的程式中需要添加一個“移除程式”功能,或者需要使用者設定一下鬧鐘,或者需要修改一下其他的系統設定,這時候也許直接調用系統自帶的控制台,要比自己修改系統資料庫自己設計消息存儲方式自己設計UI要簡單的多。
下面這個類就實作了這一功能:
1 class ControlApplet
2 {
3 public static void ShowApplet(AppletType applet)
4 {
5 ProcessStartInfo startInfo = new ProcessStartInfo();
6 startInfo.FileName = @"/Windows/ctlpnl.exe";
7 startInfo.Arguments = String.Format("cplmain.cpl,{0}", (byte)applet);
8 Process.Start(startInfo);
9 }
10
11 public static void ShowApplet(AppletType applet, byte tabIndex)
12 {
13 ProcessStartInfo startInfo = new ProcessStartInfo();
14 startInfo.FileName = @"/Windows/ctlpnl.exe";
15 startInfo.Arguments = String.Format("cplmain.cpl,{0},{1}", (byte)applet,tabIndex);
16 Process.Start(startInfo);
17 }
18
19 public enum AppletType
20 {
21 Contrast,
22 Password,
23 OwnerInformation,
24 Power,
25 Memory,
26 About,
27 Backlight,
28 AlignScreen,
29 InputMethod,
30 SoundsReminders,
31 RemovePrograms,
32 Menus,
33 Buttons,
34 TodaySettings,
35 PCConnections,
36 ModemConnections,
37 Clock,
38 NetworkConnections,
39 RegionalSettings
40 }
41
42 Constant Fields#region Constant Fields
43 public const byte CPAPPLET_OWNERINFO_IDENTIFICATION = 0;
44 public const byte CPAPPLET_OWNERINFO_NOTES = 1;
45
46 public const byte CPAPPLET_MEMORY_MAIN = 0;
47 public const byte CPAPPLET_MEMORY_RUNNINGPROGRAMS = 1;
48
49 public const byte CPAPPLET_ABOUT_VERSION = 0;
50 public const byte CPAPPLET_ABOUT_DEVICEID = 1;
51 public const byte CPAPPLET_ABOUT_COPYRIGHTS = 2;
52
53 public const byte CPAPPLET_BACKLIGHT_BATTERY = 0;
54 public const byte CPAPPLET_BACKLIGHT_EXTERNAL = 1;
55
56 public const byte CPAPPLET_INPUT_INPUTMEHTOD = 0;
57 public const byte CPAPPLET_INPUT_WORDCOMPLETION = 1;
58 public const byte CPAPPLET_INPUT_OPTIONS = 2;
59
60 public const byte CPAPPLET_SNDANDREMINDERS_VOLUME = 0;
61 public const byte CPAPPLET_SNDANDREMINDERS_SOUNDS = 1;
62 public const byte CPAPPLET_SNDANDREMINDERS_REMINDERS = 2;
63
64 public const byte CPAPPLET_MENUS_STARTMENU = 0;
65 public const byte CPAPPLET_MENUS_NEWMENU = 1;
66
67 public const byte CPAPPLET_BUTTONS_PROGRAMBUTTONS = 0;
68 public const byte CPAPPLET_BUTTONS_UPDOWNCONTROL = 1;
69
70 public const byte CPAPPLET_MODEM_CONNECTIONS = 0;
71 public const byte CPAPPLET_MODEM_DIALING = 1;
72
73 public const byte CPAPPLET_CLOCK_TIME = 0;
74 public const byte CPAPPLET_CLOCK_ALARMS = 1;
75
76 public const byte CPAPPLET_RS_REGION = 0;
77 public const byte CPAPPLET_RS_NUMBER = 1;
78 public const byte CPAPPLET_RS_CURRENCY = 2;
79 public const byte CPAPPLET_RS_TIME = 3;
80 public const byte CPAPPLET_RS_DATE = 4;
81 #endregion
82 }
簡單來說就是啟動ctlpnl.exe,并傳入相應的參數即可,注意第一個參數是表示控制台的哪一項,第二個參數(如果有的話)是表示控制台項目的具體哪個标簽頁,它為空時預設為第一個标簽頁。使用的時候如下:
ControlApplet.ShowApplet(ControlApplet.AppletType.Clock);
效果:
ControlApplet.ShowApplet(ControlApplet.AppletType.Clock,