使用API函数
SetwWindowPos(handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE+SWP_NOSIZE)
不断将当前可执行文件置于最顶层
使用自定义函数加密解密
屏幕保护,霓虹灯闪烁
空格显示解锁
显示密码
解锁成功
unit Unit4;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.pngimage, Vcl.ExtCtrls,
Vcl.StdCtrls;
type
TForm4 = class(TForm)
Image1: TImage;
Label1: TLabel;
Timer1: TTimer;
Edit1: TEdit;
Button1: TButton;
Timer2: TTimer;
CheckBox1: TCheckBox;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Button1Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
const PassWord:string='Tsinghuahuanyingni'; //密码设置
var n:integer=3;
ShowPassword: boolean=true;
Flag: boolean=true;
PassWord_1, PassWord_2:string;
function Encrypt(const InString:string; Salt:string): string;
var
i : Byte;
StartKey, MultKey, AddKey: Word;
begin
Result := '';
if (Salt = '') then begin
Result := InString;
end
else begin
StartKey := Length(Salt);
MultKey := Ord(Salt[1]);
AddKey := 0;
for i := 1 to Length(Salt) - 1 do AddKey := AddKey + Ord(Salt[i]);
for i := 1 to Length(InString) do
begin
Result := Result + CHAR(Byte(InString[i]) xor (StartKey shr 8));
StartKey := (Byte(Result[i]) + StartKey) * MultKey + AddKey;
end;
end;
end; // 自定义加密函数、原文链接:https://blog.csdn.net/xyzhan/article/details/115316766
{$R *.dfm}
procedure TForm4.CheckBox1Click(Sender: TObject);
begin
ShowPassWord:=not ShowPassWord;
if(ShowPassWord=false)then
edit1.PasswordChar:=#0
else
edit1.PasswordChar:='$';
end; //显示密码
procedure TForm4.FormCreate(Sender: TObject);
begin
Image1.Top:=0;
Image1.left:=0;
Image1.Width:=1920;
Image1.Height:=1080;
SetWindowLong(Edit1.Handle,GWL_STYLE,GetWindowLong(Edit1.Handle,GWL_STYLE) or ES_CENTER);
Edit1.Invalidate;
edit1.Visible:=false;
Button1.Visible:=false;
CheckBox1.Visible:=false; //程序初始化
end;
procedure TForm4.Timer1Timer(Sender: TObject);
begin
// SetWindowPos(handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE+SWP_NOMOVE) ; //将屏保程序置于最顶层
Label1.Font.Size:=Random(80);
Label1.Top:=Random(800);
Label1.Left:=Random(1600);
case (Random(7)) of
0:label1.Font.Color:= Clmoneygreen;
1:label1.Font.Color:= Cllime;
2:label1.Font.Color:= Clred;
3:label1.Font.Color:= Claqua;
4:label1.Font.Color:= clskyblue;
5:label1.Font.Color:= clyellow;
6:label1.Font.Color:= clpurple;
end;
case (Random(3)) of
0:label1.Font.Style:=[FsBold];
1:label1.Font.Style:=[fsItalic];
2:label1.font.Style:=[fsUnderline];//屏保霓虹灯“艰难困苦,玉汝于成”
end;
end;
procedure TForm4.Timer2Timer(Sender: TObject);
begin
Button1.Enabled:=true;
timer2.Enabled:=false; //按钮一定时间后可用
end;
procedure TForm4.Button1Click(Sender: TObject);
begin
if(Password=Edit1.Text) then
begin
MessageBox(handle,'恭喜您,密码正确!','恭喜',MB_OK);
close;
end
else
begin
n:=n-1;
if(n<1)then
begin
Label2.Visible:=false;
MessageBox(handle,'对不起,你的记忆太差。请于10秒后重试!','警告',MB_OK or MB_ICONSTOP);
Button1.Enabled:=false;
timer2.Enabled:=true;
end //冻结解锁按钮
else
begin
label2.Caption:='密码错误,您还有'+inttostr(n)+'次机会';
timer2.Enabled:=false;
end;
end;
end;
procedure TForm4.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if(Key=VK_SPACE)then
begin
edit1.Visible:=true;
Button1.Visible:=true;
CheckBox1.Visible:=true;
end
else
label1.Caption:='请按空格显示解锁';
end; //按空格显示输入解锁
end.