启动控制面板各窗口


首先复习怎样调用外部程序:
Delphi 运行外部程序是使用 Windows.WinExecShellAPI.ShellExecute, 譬如:

WinExec('notepad.exe', SW_NORMAL); {打开记事本}

WinExec('regedit.exe', SW_NORMAL); {打开注册表编辑器}


 
   
DLL 文件与 EXE 文件的主要区别就是 EXE 可以直接运行, 而 DLL 不可以;
但在 Win32 系统下, 我们可以使用系统文件 rundll32.exe 调用 DLL 中的功能;
譬如下面一句程序可以打开控制面板窗口:

WinExec('rundll32.exe shell32.dll,Control_RunDLL', SW_NORMAL); 

//可以简化一下(省略后缀):

WinExec('rundll32 shell32,Control_RunDLL', SW_NORMAL);

//SW_NORMAL 是窗口打开状态选项的常量, 它的值是 1, 为了代码简洁, 可以再简化: 

WinExec('rundll32 shell32,Control_RunDLL', 1);


 
   
本例效果图:

启动控制面板各窗口

代码文件:

unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;



type

  TForm1 = class(TForm)

    Button1: TButton;

    Button2: TButton;

    Button3: TButton;

    Button4: TButton;

    Button5: TButton;

    Button6: TButton;

    Button7: TButton;

    Button8: TButton;

    Button9: TButton;

    Button10: TButton;

    Button11: TButton;

    Button12: TButton;

    Button13: TButton;

    Button14: TButton;

    Button15: TButton;

    Button16: TButton;

    Button17: TButton;

    Button18: TButton;

    Button19: TButton;

    Button20: TButton;

    Button21: TButton;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure Button4Click(Sender: TObject);

    procedure Button5Click(Sender: TObject);

    procedure Button6Click(Sender: TObject);

    procedure Button7Click(Sender: TObject);

    procedure Button8Click(Sender: TObject);

    procedure Button9Click(Sender: TObject);

    procedure Button10Click(Sender: TObject);

    procedure Button11Click(Sender: TObject);

    procedure Button12Click(Sender: TObject);

    procedure Button13Click(Sender: TObject);

    procedure Button14Click(Sender: TObject);

    procedure Button15Click(Sender: TObject);

    procedure Button16Click(Sender: TObject);

    procedure Button17Click(Sender: TObject);

    procedure Button18Click(Sender: TObject);

    procedure Button19Click(Sender: TObject);

    procedure Button20Click(Sender: TObject);

    procedure Button21Click(Sender: TObject);

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL', 1);              {控制面板}

end;



procedure TForm1.Button2Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL access.cpl', 1);   {辅助功能选项}

end;



procedure TForm1.Button3Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL appwiz.cpl', 1);   {添加或删除程序}

end;



procedure TForm1.Button4Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL desk.cpl', 1);     {显示 属性}

end;



procedure TForm1.Button5Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL firewall.cpl', 1); {Windows 防火墙}

end;



procedure TForm1.Button6Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL hdwwiz.cpl', 1);   {添加硬件向导}

end;



procedure TForm1.Button7Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL inetcpl.cpl', 1);  {Internet 属性}

end;



procedure TForm1.Button8Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL intl.cpl', 1);     {区域和语言选项}

end;



procedure TForm1.Button9Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL irprops.cpl', 1);  {无线链接}

end;



procedure TForm1.Button10Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL joy.cpl', 1);      {游戏控制器}

end;



procedure TForm1.Button11Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL main.cpl', 1);     {鼠标 属性}

end;



procedure TForm1.Button12Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL mmsys.cpl', 1);    {声音和音频设备 属性}

end;



procedure TForm1.Button13Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL ncpa.cpl', 1);     {网络连接}

end;



procedure TForm1.Button14Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL netsetup.cpl', 1); {网络安装向导}

end;



procedure TForm1.Button15Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL nusrmgr.cpl', 1);  {用户帐号}

end;



procedure TForm1.Button16Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL odbccp32.cpl', 1); {ODBC 数据源管理器}

end;



procedure TForm1.Button17Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL powercfg.cpl', 1); {电源选项 属性}

end;



procedure TForm1.Button18Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL sysdm.cpl', 1);    {系统属性}

end;



procedure TForm1.Button19Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL telephon.cpl', 1); {电话和调制解调器选项}

end;



procedure TForm1.Button20Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL wscui.cpl', 1);    {Windows 安全中心}

end;



procedure TForm1.Button21Click(Sender: TObject);

begin

  WinExec('rundll32 shell32,Control_RunDLL wuaucpl.cpl', 1);  {自动更新}

end;



end.


 
   
窗体文件:

object Form1: TForm1

  Left = 0

  Top = 0

  Caption = 'Form1'

  ClientHeight = 227

  ClientWidth = 430

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  Position = poDesktopCenter

  PixelsPerInch = 96

  TextHeight = 13

  object Button1: TButton

    Left = 8

    Top = 8

    Width = 132

    Height = 25

    Caption = #25511#21046#38754#26495#31383#21475

    TabOrder = 0

    OnClick = Button1Click

  end

  object Button2: TButton

    Left = 8

    Top = 39

    Width = 132

    Height = 25

    Caption = #36741#21161#21151#33021#36873#39033

    TabOrder = 1

    OnClick = Button2Click

  end

  object Button3: TButton

    Left = 8

    Top = 70

    Width = 132

    Height = 25

    Caption = #28155#21152#25110#21024#38500#31243#24207

    TabOrder = 2

    OnClick = Button3Click

  end

  object Button4: TButton

    Left = 8

    Top = 101

    Width = 132

    Height = 25

    Caption = #26174#31034' '#23646#24615

    TabOrder = 3

    OnClick = Button4Click

  end

  object Button5: TButton

    Left = 8

    Top = 132

    Width = 132

    Height = 25

    Caption = 'Windows '#38450#28779#22681

    TabOrder = 4

    OnClick = Button5Click

  end

  object Button6: TButton

    Left = 8

    Top = 163

    Width = 132

    Height = 25

    Caption = #28155#21152#30828#20214#21521#23548

    TabOrder = 5

    OnClick = Button6Click

  end

  object Button7: TButton

    Left = 8

    Top = 194

    Width = 132

    Height = 25

    Caption = 'Internet '#23646#24615

    TabOrder = 6

    OnClick = Button7Click

  end

  object Button8: TButton

    Left = 150

    Top = 8

    Width = 132

    Height = 25

    Caption = #21306#22495#21644#35821#35328#36873#39033

    TabOrder = 7

    OnClick = Button8Click

  end

  object Button9: TButton

    Left = 150

    Top = 39

    Width = 132

    Height = 25

    Caption = #26080#32447#38142#25509

    TabOrder = 8

    OnClick = Button9Click

  end

  object Button10: TButton

    Left = 150

    Top = 70

    Width = 132

    Height = 25

    Caption = #28216#25103#25511#21046#22120

    TabOrder = 9

    OnClick = Button10Click

  end

  object Button11: TButton

    Left = 150

    Top = 101

    Width = 132

    Height = 25

    Caption = #40736#26631' '#23646#24615

    TabOrder = 10

    OnClick = Button11Click

  end

  object Button12: TButton

    Left = 150

    Top = 132

    Width = 132

    Height = 25

    Caption = #22768#38899#21644#38899#39057#35774#22791' '#23646#24615

    TabOrder = 11

    OnClick = Button12Click

  end

  object Button13: TButton

    Left = 150

    Top = 163

    Width = 132

    Height = 25

    Caption = #32593#32476#36830#25509

    TabOrder = 12

    OnClick = Button13Click

  end

  object Button14: TButton

    Left = 150

    Top = 194

    Width = 132

    Height = 25

    Caption = #32593#32476#23433#35013#21521#23548

    TabOrder = 13

    OnClick = Button14Click

  end

  object Button15: TButton

    Left = 291

    Top = 8

    Width = 132

    Height = 25

    Caption = #29992#25143#24080#21495

    TabOrder = 14

    OnClick = Button15Click

  end

  object Button16: TButton

    Left = 291

    Top = 39

    Width = 132

    Height = 25

    Caption = 'ODBC '#25968#25454#28304#31649#29702#22120

    TabOrder = 15

    OnClick = Button16Click

  end

  object Button17: TButton

    Left = 291

    Top = 70

    Width = 132

    Height = 25

    Caption = #30005#28304#36873#39033' '#23646#24615

    TabOrder = 16

    OnClick = Button17Click

  end

  object Button18: TButton

    Left = 291

    Top = 101

    Width = 132

    Height = 25

    Caption = #31995#32479#23646#24615

    TabOrder = 17

    OnClick = Button18Click

  end

  object Button19: TButton

    Left = 291

    Top = 132

    Width = 132

    Height = 25

    Caption = #30005#35805#21644#35843#21046#35299#35843#22120#36873#39033

    TabOrder = 18

    OnClick = Button19Click

  end

  object Button20: TButton

    Left = 291

    Top = 163

    Width = 132

    Height = 25

    Caption = 'Windows '#23433#20840#20013#24515

    TabOrder = 19

    OnClick = Button20Click

  end

  object Button21: TButton

    Left = 291

    Top = 194

    Width = 132

    Height = 25

    Caption = #33258#21160#26356#26032

    TabOrder = 20

    OnClick = Button21Click

  end

end


 
   

你可能感兴趣的:(启动)