因需要做一个特色屏保,安装在每位员工的电脑上运行,同时为在一定程度上防止职员随意更换其它屏保,特做一个关于屏保显示页面控制的小程序。。。。Delphi代码如下:
显示效果:
//工程文件 program Project1; uses Forms, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. //单元文件 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Label2: TLabel; StatusBar1: TStatusBar; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Registry; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var reg : TRegistry; begin try reg := TRegistry.Create; reg.RootKey := HKEY_CURRENT_USER; reg.openkey('software\microsoft\windows\currentversion\policies\system',true); if reg.ValueExists('Nodispscrsavpage') then begin if reg.ReadString('Nodispscrsavpage') = '1' then begin reg.DeleteValue('Nodispscrsavpage'); //显示 投置选项 end else begin reg.WriteString('Nodispscrsavpage','1'); //隐藏 end; end else begin reg.WriteString('Nodispscrsavpage','1'); end; //根据结果判断是否修改成功 if reg.ValueExists('Nodispscrsavpage') then begin if reg.ReadString('Nodispscrsavpage') = '1' then begin //是隐藏状态 label2.Caption := '隐 藏'; button1.Caption := '显 示'; end else begin //显示状态 label2.Caption := '显 示'; button1.Caption := '隐 藏'; end; end else begin //显示状态 label2.Caption := '显 示'; button1.Caption := '隐 藏'; end; finally reg.CloseKey; reg.Free; end; end; procedure TForm1.FormCreate(Sender: TObject); var reg : TRegistry; stmp : String; begin reg := TRegistry.Create; reg.RootKey := HKEY_CURRENT_USER; reg.openkey('software\microsoft\windows\currentversion\policies\system',true); stmp := reg.ReadString('Nodispscrsavpage'); if stmp <> '1' then begin label2.Caption := '显 示'; button1.Caption := '隐 藏'; end else begin label2.Caption := '隐 藏'; button1.Caption := '显 示'; end; reg.CloseKey; reg.Free; end; end. //窗体代码 object Form1: TForm1 Left = 185 Top = 173 BorderIcons = [biSystemMenu, biMinimize] Caption = #23631#20445#25511#21046#20462#25913 ClientHeight = 169 ClientWidth = 234 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False Position = poScreenCenter OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object Label1: TLabel Left = 8 Top = 16 Width = 130 Height = 22 AutoSize = False Caption = #24403#21069#25511#21046#23646#24615#29366#24577#65306 end object Label2: TLabel Left = 145 Top = 11 Width = 81 Height = 27 AutoSize = False Font.Charset = GB2312_CHARSET Font.Color = clFuchsia Font.Height = -19 Font.Name = #21326#25991#38582#20070 Font.Style = [] ParentFont = False end object Button1: TButton Left = 40 Top = 85 Width = 153 Height = 52 Font.Charset = GB2312_CHARSET Font.Color = clNavy Font.Height = -24 Font.Name = #24188#22278 Font.Style = [fsBold] ParentFont = False TabOrder = 0 OnClick = Button1Click end object StatusBar1: TStatusBar Left = 0 Top = 150 Width = 234 Height = 19 Panels = < item Text = 'CopyRight by BoltWolf ---2011.06.01' Width = 50 end> end end