调用Windows Mobile自带的控制面板项
如何在程序中调用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
82
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

82

简单来说就是启动ctlpnl.exe,并传入相应的参数即可,注意第一个参数是表示控制台的哪一项,第二个参数(如果有的话)是表示控制台项目的具体哪个标签页,它为空时默认为第一个标签页。使用的时候如下:
ControlApplet.ShowApplet(ControlApplet.AppletType.Clock);
效果:
ControlApplet.ShowApplet(ControlApplet.AppletType.Clock,
ControlApplet.CPAPPLET_CLOCK_ALARMS);
ControlApplet.CPAPPLET_CLOCK_ALARMS);
效果:
完整示例在这里下载:
https://files.cnblogs.com/fox23/ControlPanelSample.rar
Enjoy!
相关资料: