首页/技术开发/内容

用C++Builder 5开发Windows下的屏保

技术开发2023-12-25 阅读()
frequence>6)
     frequence=2;
    Timer1->Interval=1000*frequence;设置定时器
  }
  __finally
  {
    delete Registry;
    picdir="no";
  }
    //检测是否运行于 NT下
    if(Version!=0)
    if(PWProtect&&Version>0x80000000)//如果系统要求密码保护并此系统为非NT那么把系统设为屏保
状态
     SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, 0, 0);
    //使光标消失
    while (!ShowCursor(false)< -5);
}
//---------------------------------------------------------------------------
void __fastcall TFrmmain::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TFrmmain::FormMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TFrmmain::FormCloseQuery(TObject *Sender, bool &CanClose)
{
if (PWProtect && Version>0x80000000)
      {
        bool PassChck;
       //显示光标,并调用密码对话框
        while(!ShowCursor(True) > 5);
       //以下是VerifyScreenSavePwd函数的动态调用
        typedef UINT(CALLBACK *FUN)(HWND);
                   HINSTANCE hDll=LoadLibrary("password.cpl");
                   FUN myfun;
                   if(hDll!=NULL)
                    {
                     myfun=(FUN)GetProcAddress(hDll,"VerifyScreenSavePwd");
                     if(!myfun)FreeLibrary(hDll);
                     else
                     PassChck=myfun(this->Handle);
                    }
        if(PassChck == false)
          {
            while(!ShowCursor(False) < -5);
            CanClose = false;
           }
      }
}
//---------------------------------------------------------------------------

void __fastcall TFrmmain::FormClose(TObject *Sender, TCloseAction &Action)
{
while(!ShowCursor(True) > 5);
    if(PWProtect&&Version>0x80000000)
        SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, 0, 0);//退出屏保状态
}
//---------------------------------------------------------------------------
void __fastcall TFrmmain::Image1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TFrmmain::Image1MouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{   static int MouseMoves=0;
    MouseMoves = MouseMoves + 1;
    if(MouseMoves >4)
     {
     this->Close();
     MouseMoves = 0 ;
     }
}
//---------------------------------------------------------------------------
void __fastcall TFrmmain::Timer1Timer(TObject *Sender)
{
if(picdir=="no")
{
int i ;
randomize();
i=rand()%2;
if(i==0)
i=-1;
else
i=1;
Image1->Top=i*(rand()%this->Height);
Image1->Left=i*(rand()%this->Width);
}
}
//---------------------------------------------------------------------------
/*{*******************************}*/
/*{*****   Unitcontrol.h   ****}*/
/*{*******************************}*/
//---------------------------------------------------------------------------
#ifndef UnitcontrolH
#define UnitcontrolH
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TFrmControl : public TForm
{
__published: // IDE-managed Components
        TImage *Image1;
        TTimer *Timer1;
        void __fastcall Timer1Timer(TObject *Sender);
        void __fastcall FormCreate(TObject *Sender);
private: // User declarations
public: // User declarations
        __fastcall TFrmControl(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFrmControl *FrmControl;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
/*{*******************************}*/
/*{*****   Unitcontrol.cpp ****}*/
/*{*******************************}*/
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unitcontrol.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrmControl *FrmControl;
//---------------------------------------------------------------------------
__fastcall TFrmControl::TFrmControl(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFrmControl::Timer1Timer(TObject *Sender)
{
int i ;
randomize();
i=rand()%2;
if(i==0)
i=-1;
else
i=1;
Image1->Top=i*(rand()%this->Height);
Image1->Left=i*(rand()%this->Width);
}
//---------------------------------------------------------------------------
void __fastcall TFrmControl::FormCreate(TObject *Sender)
{
Image1->Top=0;
Image1->Left=0;
Image1->Height=this->Height ;
Image1->Width=this->Width ;
}
//---------------------------------------------------------------------------
/*{*******************************}*/
/*{*****    Unitconfig.h   ****}*/
/*{*******************************}*/
//---------------------------------------------------------------------------
#ifndef UnitconfigH
#define UnitconfigH
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TFrmConfig : public TForm
{
__published: // IDE-managed Components
        TPanel *Panel1;
        TButton *Button1;
        TPanel *Panel2;
        TLabel *Label1;
        TTrackBar *TrackBar1;
        TLabel *Label2;
        TLabel *Label3;
        TLabel *Label4;
        TButton *Button2;
        void __fastcall Button1Click(TObject *Sender);
        void __fastcall Button2Click(TObject *Sender);
private: // User declarations
  AnsiString picdir;
  int frequence;
public: // User declarations
        __fastcall TFrmConfig(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFrmConfig *FrmConfig;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
/*{*******************************}*/
/*{*****   Unitconfig.cpp  ****}*/
/*{*******************************}*/
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unitconfig.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrmConfig *FrmConfig;
//---------------------------------------------------------------------------
__fastcall TFrmConfig::TFrmConfig(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFrmConfig::Button1Click(TObject *Sender)
{
if(SelectDirectory("Select Picture Dir","",picdir))
   Panel2->Caption=picdir;
}
//---------------------------------------------------------------------------
void __fastcall TFrmConfig::Button2Click(TObject *Sender)
{
//把信息写入注册表
if(picdir=="") picdir="no";
this->frequence=TrackBar1->Position;
TRegistry *Reg = new TRegistry;
  try
   {
    Reg->RootKey = HKEY_CURRENT_USER;
    if (Reg->OpenKey("\\Software\\CODEHUNTER", true))
    {
      Reg->WriteString("PicDir",picdir);
      Reg->WriteInteger("frequence",frequence);
      Reg->CloseKey();
    }
  }
  __finally
  {
    delete Reg;
  }
this->Close();
}
//---------------------------------------------------------------------------
                                                                  
源代码下载(http://codehunter.1yes.net/download/lucysaver.zip)

第1页  第2页  第3页  第4页  第5页  第6页  第7页 

……

相关阅读