[VB.NET]访问控制面板

访问控制面板

实例说明

在本实例中,我们制作一个能够访问控制面板各个选项的应用程序。点击不同按钮,即可打开相应的程序。程序运行结果如图93-1所示。

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

图93-1 运行结果

技术要点

l Shell()函数

l 按钮的图形化

l 运行进程和等待进程

l 结束进程

实现过程

■ 新建项目

打开Visual Studio.NET,选择"新建项目",在项目类型窗口中选择"Visual Basic项目",在模板窗口中选择"Windows应用程序",在名称域中输入"ControlPad",然后选择保存路径。单击"确认"。

■ 添加控件

向当前窗体上添加九个Button按钮。

■ 设置属性

切换到"属性栏",对窗体及控件设置属性,如表93-1所示。

表93-1 窗体及控件的属性值

窗体/控件 属性 值

Form1 StartUpPosition 2-屏幕中心

Picture App.path & "/jpg/jshb.jpg"

Button Caption 空

Picture App.path & "/jpg/system.jpg"

Style 1-Graphical

其他Label控件 Autosize True

Caption 跟界面一致

■ 添加代码

Option Strict Off

Friend Class Form1

Inherits System.Windows.Forms.Form

Const SYNCHRONIZE As Integer = &H100000

Const INFINITE As Integer = &HFFFFFFFF

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Integer, ByVal dwMilliseconds As Integer) As Integer

Private Sub cmdcontrol_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdcontrol.Click

Dim Index As Short = cmdcontrol.GetIndex(eventSender)

Dim strres As String

Select Case Index

Case 0

strres = "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl "

Case 1

strres = "rundll32.exe shell32.dll,Control_RunDLL desk.cpl"

Case 2

strres = "rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl @1"

Case 3

strres = "rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl"

Case 4

strres = "rundll32.exe shell32.dll,Control_RunDLL password.cpl"

Case 5

strres = "rundll32.exe shell32.dll,Control_RunDLL powercfg.cpl"

Case 6

strres = "rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl"

Case 7

strres = "rundll32.exe shell32.dll,Control_RunDLL modem.cpl"

Case 8

strres = "rundll32.exe shell32.dll,Control_RunDLL netcpl.cpl"

Case Else

End Select

ExeControlPad(strres)

End Sub

Function ExeControlPad(ByVal lpparam As String) As Object

Dim pId, pHnd As Integer

pId = Shell(lpparam, AppWinStyle.NormalFocus)

' 取得 Process Handle

pHnd = OpenProcess(SYNCHRONIZE, 0, pId)

If pHnd <> 0 Then

' 等待程序结束

Call WaitForSingleObject(pHnd, INFINITE)

Call CloseHandle(pHnd)

End If

End Function

End Class

■ 运行程序

单击菜单"调试|启动"或单击 图标运行程序。

小结

本实例中仅访问了控制面板中的九个选项,读者可以自行增加选项,下面在表93-2中列出控制面板中各组件的常量参数。

表93-2 控制面板各组件的参数值

控制面板各组件 值 控制面板各组件 值

Internet Inetcpl.cpl 密码 Password.cpl

MS DTC Dtccfg.cpl 区域设置 Intl.cpl

ODBC数据源 Odbccp32.cpl 日期/时间 Timedate.cpl

打印机 Main.cpl @2 声音 Mmsys.cpl @1

电话 Telephone.cpl 输入法 Main.cop @4

电源管理 Powercfg.cpl 鼠标 Main.cpl @0

调制解调器 Modem.cpl 添加/删除程序 Appwiz.cpl

多媒体 Mmsys.cpl 添加新硬件 Sysdm.cpl @1

辅助选项 Access.cpl 网络 Netcpl.cpl

键盘 Main.cpl @1 系统 Sysdm.cpl

游戏控制器 Joy.cpl 显示 Desk.cpl

字体 Main.cpl @3 扫描仪与数字相机 Sticpl.cpl

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值