[VB.NET]访问控制面板
访问控制面板
实例说明 在本实例中,我们制作一个能够访问控制面板各个选项的应用程序。点击不同按钮,即可打开相应的程序。程序运行结果如图93-1所示。 图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,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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |