|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 xieyuan0553 于 2017-2-18 08:59 编辑
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,Imm;
type
TShutDownStatus=(sdShutDown,sdReboot,sdLogOff,sdPowerOff);
TFormScreen = class(TForm)
Image1: TImage;
LabelScreen: TLabel;
Timer1: TTimer;
EditPassword: TEdit;
ButtonOK: TButton;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ButtonOKClick(Sender: TObject);
procedure CloseImm;
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormScreen: TFormScreen;
implementation
const
Password:String='1234567890';
var
Flag:Boolean=True;
i:Integer=3;
{$R *.dfm}
procedure TFormScreen.CloseImm;
var
MyHkl:Hkl;
begin
MyHkl:=GetKeyBoardLayOut(0);
if ImmIsIME(MyHkl) then
ImmsImulateHotKey(Handle,IME_CHotKey_IME_NonIME_Toggle);
end;
procedure TFormScreen.FormCreate(Sender: TObject);
var
Bmp:TBitmap;
Can:TCanvas;
DC:HDC;
begin
Bmp:=TBitmap.Create;
Bmp.Width:=Screen.Width;
Bmp.Height:=Screen.Height;
DC:=GetDC(0);
Can:=TCanvas.Create;
Can.Handle:=DC;
Bmp.Canvas.CopyRect(Rect(0,0,Screen.Width,Screen.Height),Canvas,Rect(0,0,Screen.Width,Screen.Height));
Image1.Picture.Bitmap:=Bmp;
Bmp.Free;
ReleaseDC(0,DC);
SetWindowLong(EditPassword.Handle,GWL_STYLE,GetWindowLong(EditPassword.Handle,GWL_STYLE) or ES_CENTER);
EditPassword.Invalidate;
EditPassword.Visible:=False;
ButtonOK.Visible:=False;
CloseImm;
end;
procedure TFormScreen.Timer1Timer(Sender: TObject);
begin
SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE+SWP_NOMOVE);
LabelScreen.Left:=Random(Screen.Width-LabelScreen.Width);
LabelScreen.Top:=Random(Screen.Height-LabelScreen.Height);
LabelScreen.Font.Size:=Random(25);
Case (Random(5)) of
0:LabelScreen.Font.Color:=clRed;
1:LabelScreen.Font.Color:=clGreen;
2:LabelScreen.Font.Color:=clYellow;
3:LabelScreen.Font.Color:=clBlack;
4:LabelScreen.Font.Color:=clOlive;
end;
Case (Random(2)) of
0:LabelScreen.Color:=clWhite;
1:LabelScreen.Color:=clNavy;
2:LabelScreen.Color:=clFuchsia;
end;
end;
procedure TFormScreen.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key=VK_SPACE) and (Flag=True) then
begin
EditPassword.Visible:=True;
ButtonOK.Visible:=True;
end
else
begin
if Flag=False then
MessageBox(Handle,'输入密码错误次数太多,系统即将关机!!!','警告',MB_ICONSTOP+MB_OK)
else
MessageBox(Handle,'请按下空格并输入密码解锁','提醒',MB_ICONWARNING+MB_OK);
end;
end;
procedure TFormScreen.ButtonOKClick(Sender: TObject);
var
NewState:TTokenPrivileges;
LpLuid:Int64;
ReturnLength:DWORD;
TokenHandle:Cardinal;
begin
if EditPassword.Text=Password then
Close
else
if i>0 then
begin
MessageBox(Handle,PChar('密码错误!!!你还有'+IntToStr(i)+'次机会。'),'警告',MB_ICONWARNING+MB_OK);
i:=i-1;
EditPassword.Text:='';
end
else
begin
MessageBox(Handle,'输入密码错误次数太多,系统即将关机!!!','警告',MB_ICONSTOP+MB_OK);
begin
OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES OR TOKEN_ALL_ACCESS OR STANDARD_RIGHTS_REQUIRED OR TOKEN_QUERY,TokenHandle);
LookupPrivilegeValue(nil,'SeShutDownPrivilege',LpLuid);
NewState.PrivilegeCount:=1;
NewState.Privileges[0].Luid:=LpLuid;
NewState.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
ReturnLength:=0;
AdjustTokenPrivileges(TokenHandle,False,NewState,0,nil,ReturnLength);
ExitWindowsEx(EWX_SHUTDOWN OR EWX_POWEROFF OR EWX_FORCE,0);
end;
end;
end;
end.
特点:
1.当你打开屏幕保护程序的时候,系统自动切换到英文输入法。
2.屏幕截图是用代码的形式写出来的。
3.当你密码连续3次输入错误的时候,系统就关机。 |
|