⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 一个简单的可以在windows平台实现锁屏的小程序源代码。
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include<tlhelp32.h>
#include "Unit1.h"
#include <FileCtrl.hpp>
#include<fstream.h>
#include <Registry.hpp>
 typedef BOOL (CALLBACK* tagDisableKB)(bool disable);
tagDisableKB DisableKB1;

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
  int ProcessID[1000];
  int gettheend;
  int  needctrl;
  int needalt;
  int firstnow;
  TRect r = Rect(0,0,1,1);
  int mouse=0;
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{

      int a=0;
 HANDLE   ProcessListHandle= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
          // 产生进程列表句柄

      int i=0;

      PROCESSENTRY32  ProcessStruct;
      ProcessStruct.dwSize=sizeof(ProcessStruct);
      int yn=Process32First(ProcessListHandle,
                             &ProcessStruct);
      while (yn!=0)
         {
             ProcessID[i++]=ProcessStruct.th32ProcessID;

            AnsiString abc=ProcessStruct.szExeFile;
        if(abc=="taskmgr.exe")
           {
            a= ProcessStruct.th32ProcessID;
            TerminateProcess(OpenProcess(PROCESS_ALL_ACCESS,0,a),
        0);
}

         yn=Process32Next(ProcessListHandle,&ProcessStruct);
         }




}
//---------------------------------------------------------------------------
  void __fastcall TForm1::WndProc(TMessage &msg)
{
 if (msg.Msg == WM_SYSCOMMAND)
  if (msg.WParam == SC_CLOSE)
   msg.WParam = 0;
 TForm::WndProc(msg);
}

AnsiString filename;
AnsiString filedir;

void __fastcall TForm1::FormCreate(TObject *Sender)
{

filename=ExtractFileName(Application->ExeName);
filedir=ExtractFilePath(Application->ExeName);
filename=filedir+filename;

TRegistry *Reg;
Reg=new TRegistry();
Reg->RootKey=HKEY_LOCAL_MACHINE;

if(!Reg->KeyExists("SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\屏幕锁") )
{
 Reg->CreateKey("SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\屏幕锁");
Reg->OpenKey("SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\屏幕锁",false)  ;
Reg->WriteString("锁",filename.c_str());
Reg->WriteInteger("结束键",20);
Reg->WriteInteger("是否第一次",1);
Reg->WriteInteger("ctrl",1);
Reg->WriteInteger("alt",1);
}



Reg->OpenKey("SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\屏幕锁",false)  ;
gettheend=Reg->ReadInteger("结束键");
firstnow=Reg->ReadInteger("是否第一次");
needctrl=Reg->ReadInteger("ctrl");
needalt=Reg->ReadInteger("alt");




if(firstnow==1)
{
Form1->WindowState=wsNormal;
}
else
{
Form1->Brush->Style=bsClear;
Form1->BorderStyle=bsNone;
Form1->CheckBox1->Visible=false;
Form1->Label1->Visible=false;
Form1->CheckBox2->Visible=false;
Form1->CheckBox3->Visible=false;
Form1->Edit1->Visible=false;
Form1->Label2->Visible=false;
Form1->Label3->Visible=false;
Form1->Label4->Visible=false;
Form1->Label5->Visible=false;
Form1->Button1->Visible=false;
Form1->Label6->Visible=false;
Form1->Label7->Visible=false;
Form1->Button2->Visible=false;
Form1->Label8->Visible=false;
Form1->Button3->Visible=false;
Form1->Label9->Visible=false;
Form1->Label10->Visible=false;
}


firstnow=firstnow+1;
Reg->WriteInteger("是否第一次",firstnow);

delete Reg;

hInst = LoadLibrary("shell32.dll");
DisableKB1 = (tagDisableKB)GetProcAddress(hInst, "DisableKB");

DisableKB(true);


}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
TRegistry *Reg;
Reg=new TRegistry();
Reg->RootKey=HKEY_LOCAL_MACHINE;
Reg->OpenKey("SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\屏幕锁",false)  ;

int ctrl;
int alt;
int hotkey;
ctrl=Reg->ReadInteger("ctrl");
alt=Reg->ReadInteger("alt");
hotkey=Reg->ReadInteger("结束键");

if(ctrl==1 && alt==1)
{
  if(Shift.Contains(ssCtrl) && Shift.Contains(ssAlt))
    {
         if (Key==hotkey)
            {
               mouse=1;
               if(Application->MessageBoxA("屏幕解锁","选择’是‘退出,选择’否‘进行设置",MB_YESNO)==IDYES)
                  {Application->Terminate(); }
              else
                  {
                 Form1->Brush->Style = bsSolid;
                 Form1->BorderStyle=bsSingle;
                 Form1->Color=clBtnFace;
                 Form1->Height=267;
                 Form1->Width=454;
                 Form1->Left=0.5*(Screen->Width-Form1->Width);
                 Form1->Top =0.5*(Screen->Height-Form1->Height);
                 Form1->CheckBox1->Visible=true;
                 Form1->Label1->Visible=true;
                 Form1->CheckBox2->Visible=true;
                 Form1->CheckBox3->Visible=true;
                 Form1->Edit1->Visible=true;
                 Form1->Label2->Visible=true;
                 Form1->Label3->Visible=true;
                 Form1->Label4->Visible=true;
                 Form1->Label5->Visible=true;
                 Form1->Button1->Visible=true;
                 Form1->Label6->Visible=true;
                 Form1->Label7->Visible=true;
                 Form1->Button2->Visible=true;
                 Form1->Label8->Visible=true;
                 Form1->Button3->Visible=true;
                 Form1->Label9->Visible=true;
                 Form1->Label10->Visible=true;
                  }
             }
    }
}

if(ctrl==1 && alt==0)
{
  if(Shift.Contains(ssCtrl))
    {
         if (Key==hotkey)
            {   mouse=1;
              if(Application->MessageBoxA("屏幕解锁","选择’是‘退出,选择’否‘进行设置",MB_YESNO)==IDYES)
                  {Application->Terminate(); }
              else
                  {
                 Form1->Brush->Style = bsSolid;
                 Form1->BorderStyle=bsSingle;
                 Form1->Color=clBtnFace;
                 Form1->Height=267;
                 Form1->Width=454;
                 Form1->Left=0.5*(Screen->Width-Form1->Width);
                 Form1->Top =0.5*(Screen->Height-Form1->Height);
                 Form1->CheckBox1->Visible=true;
                 Form1->Label1->Visible=true;
                 Form1->CheckBox2->Visible=true;
                 Form1->CheckBox3->Visible=true;
                 Form1->Edit1->Visible=true;
                 Form1->Label2->Visible=true;
                 Form1->Label3->Visible=true;
                 Form1->Label4->Visible=true;
                 Form1->Label5->Visible=true;
                 Form1->Button1->Visible=true;
                 Form1->Label6->Visible=true;
                 Form1->Label7->Visible=true;
                 Form1->Button2->Visible=true;
                 Form1->Label8->Visible=true;
                 Form1->Button3->Visible=true;
                 Form1->Label9->Visible=true;
                 Form1->Label10->Visible=true;
                  }
             }
    }
}

 if(ctrl==0 && alt==1)
{
  if( Shift.Contains(ssAlt))
    {
         if (Key==hotkey)
            {    mouse=1;
              if(Application->MessageBoxA("屏幕解锁","选择’是‘退出,选择’否‘进行设置",MB_YESNO)==IDYES)
                  {Application->Terminate(); }
              else
                  {
                 Form1->Brush->Style = bsSolid;
                 Form1->BorderStyle=bsSingle;
                 Form1->Color=clBtnFace;
                 Form1->Height=267;
                 Form1->Width=454;
                 Form1->Left=0.5*(Screen->Width-Form1->Width);
                 Form1->Top =0.5*(Screen->Height-Form1->Height);
                 Form1->CheckBox1->Visible=true;
                 Form1->Label1->Visible=true;
                 Form1->CheckBox2->Visible=true;
                 Form1->CheckBox3->Visible=true;
                 Form1->Edit1->Visible=true;
                 Form1->Label2->Visible=true;
                 Form1->Label3->Visible=true;
                 Form1->Label4->Visible=true;
                 Form1->Label5->Visible=true;
                 Form1->Button1->Visible=true;
                 Form1->Label6->Visible=true;
                 Form1->Label7->Visible=true;
                 Form1->Button2->Visible=true;
                 Form1->Label8->Visible=true;
                 Form1->Button3->Visible=true;
                 Form1->Label9->Visible=true;
                 Form1->Label10->Visible=true;
                  }
             }
    }
}

 if(ctrl==0 && alt==0)
{
            if (Key==hotkey)
             {     mouse=1;
              if(Application->MessageBoxA("屏幕解锁","选择’是‘退出,选择’否‘进行设置",MB_YESNO)==IDYES)
                  {Application->Terminate(); }
              else
                  {
                 Form1->Brush->Style = bsSolid;
                 Form1->BorderStyle=bsSingle;
                 Form1->Color=clBtnFace;
                 Form1->Height=267;
                 Form1->Width=454;
                 Form1->Left=0.5*(Screen->Width-Form1->Width);
                 Form1->Top =0.5*(Screen->Height-Form1->Height);
                 Form1->CheckBox1->Visible=true;
                 Form1->Label1->Visible=true;
                 Form1->CheckBox2->Visible=true;
                 Form1->CheckBox3->Visible=true;
                 Form1->Edit1->Visible=true;
                 Form1->Label2->Visible=true;
                 Form1->Label3->Visible=true;
                 Form1->Label4->Visible=true;
                 Form1->Label5->Visible=true;
                 Form1->Button1->Visible=true;
                 Form1->Label6->Visible=true;
                 Form1->Label7->Visible=true;
                 Form1->Button2->Visible=true;
                 Form1->Label8->Visible=true;
                 Form1->Button3->Visible=true;
                 Form1->Label9->Visible=true;
                 Form1->Label10->Visible=true;
                  }
             }
}




   if (Shift.Contains(ssCtrl) && Shift.Contains(ssAlt))                              //这个地方,是我写的时候害怕忘了上次的密码
  {if (Key==73)                                                                       //随便设定的一个值
{Application->MessageBoxA("屏幕已解锁","曾民 2003.5.10 与成都电子科技大学",MB_OK) ;
Application->Terminate();}
  }


}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 if(Application->MessageBoxA("确定吗?如果确定,请记住你的热键","确定对话框",MB_OKCANCEL)==IDOK)
{
TRegistry *Reg;
Reg=new TRegistry();
Reg->RootKey=HKEY_LOCAL_MACHINE;
Reg->OpenKey("SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\屏幕锁",false)  ;
if(Form1->CheckBox1->Checked==false)
{Reg->DeleteValue("锁");}
else
{Reg->WriteString("锁",filename.c_str()); }

if(Form1->CheckBox2->Checked==false)
{Reg->WriteInteger("ctrl",0);}
else
{Reg->WriteInteger("ctrl",1); }

if(Form1->CheckBox3->Checked==false)
{Reg->WriteInteger("alt",0);}
else
{Reg->WriteInteger("alt",1); }

int hotkey;
if(Edit1->Text=="")
hotkey=0;
else
hotkey=StrToInt(Edit1->Text);
if(hotkey!=0)
Reg->WriteInteger("结束键",hotkey);
else
{
ShowMessage("你必须选择一个组合键");
return ;
 }
delete Reg;
}
else
return ;


 if(firstnow==2)
{ShowMessage("已保存您的设置,请重新启动一次程序");  }


Application->Terminate();
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button2KeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
ShowMessage(Key);        
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button3Click(TObject *Sender)
{
 if(Application->MessageBoxA("确定吗?清除以后你的系统就象没有用过该软件一样,而且不影响以后再次使用","确定对话框",MB_OKCANCEL)==IDOK)
   {
TRegistry *Reg;
Reg=new TRegistry();
Reg->RootKey=HKEY_LOCAL_MACHINE;
Reg->OpenKey("SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN",false);
Reg->DeleteKey("屏幕锁");
delete Reg;
Application->Terminate();
   }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
if(firstnow>2 && mouse==0)
 ClipCursor(&r);


}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -