Unitcontrol.cpp
上传用户:cqslgg
上传日期:2009-12-10
资源大小:128k
文件大小:11k
源码类别:

Delphi/CppBuilder

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <stdlib.h>
  5. #include <Registry.hpp>
  6. #include <jpeg.hpp>
  7. #include "Unitcontrol.h"
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma resource "*.dfm"
  11. TMainForm *MainForm;
  12. //---------------------------------------------------------------------------
  13. __fastcall TMainForm::TMainForm(TComponent* Owner)
  14.         : TForm(Owner)
  15. {
  16.   bussy=false;
  17.   stoploop=false;
  18.   stopcls=false;
  19. }
  20. //---------------------------------------------------------------------------
  21. void __fastcall TMainForm::Fade(Graphics::TBitmap *Pic,TCanvas *dest)
  22. {
  23.  int style,x,y,devide;
  24.  int picwidth=Pic->Width ;
  25.  int picheight=Pic->Height ;
  26.  TRect rect1,rect2;
  27.  const block=10;
  28.  devide=picheight/block;
  29.  randomize();
  30.  style=random(5);
  31.  x=random(this->ClientWidth-Pic->Width);
  32.  y=random(this->ClientHeight-Pic->Height);
  33.  Timer1->Enabled=false;
  34.  switch (style)
  35.  {
  36.    case 0:
  37.     for(int i=0;i<devide;i++)
  38.     {if(!stoploop){
  39.      rect1=Rect(0,i*block,picwidth,block*(i+1));
  40.      rect2=Rect(x,y+block*i,picwidth+x,y+block*(i+1));
  41.      dest->CopyRect(rect2,Pic->Canvas,rect1);
  42.      Application->ProcessMessages();
  43.      Sleep(100);}
  44.      else
  45.      break;
  46.      }
  47.    break;
  48.    case 1:
  49.      for(int i=devide;i>=0;i--)
  50.      {
  51.      if(!stoploop){
  52.      rect1=Rect(0,i*block,picwidth,block*(i+1));
  53.      rect2=Rect(x,y+block*i,picwidth+x,y+block*(i+1));
  54.      dest->CopyRect(rect2,Pic->Canvas,rect1);
  55.      Application->ProcessMessages();
  56.      Sleep(100); }
  57.      else
  58.      break;
  59.      }
  60.    break;
  61.    case 2:
  62.      for(int i=x;i>=0;i--)
  63.        {if(!stoploop){
  64.         dest->Draw(i,y,Pic);
  65.         y--;
  66.         Application->ProcessMessages();
  67.         Sleep(10);}
  68.         else
  69.         break;
  70.        }
  71.    break;
  72.    case 3:
  73.       for(int i=picwidth/block-1;i>=0;i--)
  74.      {if(!stoploop){
  75.      rect1=Rect(i*block,0,(i+1)*block,picheight);
  76.      rect2=Rect(x+i*block,y,x+(i+1)*block,picheight);
  77.      dest->CopyRect(rect2,Pic->Canvas,rect1);
  78.      Application->ProcessMessages();
  79.      Sleep(100);}
  80.      else
  81.      break;
  82.      }
  83.    break;
  84.   default:
  85.    {dest->Draw(x,y,Pic) ;
  86.     Sleep(100);}
  87.  }
  88.    Timer1->Enabled=true;
  89. }
  90. void __fastcall TMainForm::Timer1Timer(TObject *Sender)
  91. {
  92. stoploop=false;
  93. if(picdir=="no"){
  94. Graphics::TBitmap *srcimg;
  95. srcimg=new Graphics::TBitmap();
  96. randomize();
  97. try
  98. {
  99. srcimg->LoadFromResourceID((int)HInstance,random(7));
  100. this->Fade(srcimg,this->Canvas);
  101. this->clsscreen(Image1);
  102. }
  103. catch(...)
  104. {
  105. srcimg->Free();
  106. Timer1->Enabled=true;
  107. }
  108. this->Canvas->FillRect(Rect(0,0,this->ClientWidth,this->ClientHeight));
  109. }
  110. else
  111. {int s=0;
  112.  s=random(File1->Items->Count);
  113.  try
  114.   {
  115.   if(this->Height>Image1->Height&&this->Width>Image1->Width)
  116.   {Image1->Top=rand()%(this->Height-Image1->Height);
  117.   Image1->Left=rand()%(this->Width-Image1->Width);}
  118.   else
  119.   {
  120.   Image1->Top =0;
  121.   Image1->Left=0;
  122.   }
  123.   Image1->Picture->LoadFromFile(File1->Items->Strings[s]);
  124.   this->clsscreen(Image1);
  125.  /*  Image1->Canvas->Brush->Color=clBlack;
  126.  for(int i=0;i<100;i++){
  127.   if(!stoploop){
  128.   Image1->Canvas->Ellipse(random(Image1->ClientWidth),random(Image1->ClientHeight) , random(Image1->Width/10), random(Image1->ClientHeight/10));
  129.   Application->ProcessMessages();
  130.   Sleep(100);
  131.   }*/
  132.  }
  133. catch(...)
  134. {
  135. }
  136. }
  137. }
  138. //---------------------------------------------------------------------------
  139. void __fastcall TMainForm::FormCreate(TObject *Sender)
  140. {
  141.     SetWindowPos(this->Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
  142.     //Make the form exactly cover the screen
  143.     this->Width=Screen->Width;
  144.     this->Height=Screen->Height;
  145.     this->Top=0;
  146.     this->Left=0;
  147.     this->Canvas->Brush->Color=clBlack;
  148.     stoploop=false;
  149.     Version=GetVersion();
  150.     TRegistry *Registry = new TRegistry;
  151.   try
  152.   {
  153.     if(Version>0x80000000){
  154.     Registry->RootKey =HKEY_CURRENT_USER;
  155.     Registry->OpenKey("\Control Panel\Desktop",false);
  156.     PWProtect=Registry->ReadInteger("ScreenSaveUsePassword");
  157.     Registry->CloseKey();}
  158.     Registry->RootKey =HKEY_CURRENT_USER;
  159.     if(Registry->OpenKey("\Software\CODEHUNTER", false)){
  160.     picdir=Registry->ReadString("PicDir");
  161.     frequence=Registry->ReadInteger("frequence");}
  162.     else
  163.     {
  164.     Registry->CreateKey("\Software\CODEHUNTER");
  165.     Registry->WriteString("PicDir","no");
  166.     Registry->WriteInteger("frequence",3);
  167.     picdir="no";
  168.     }
  169.     if(frequence<=0||frequence>6)
  170.      frequence=3;
  171.     if(picdir!="no"){File1->Directory=picdir;
  172.     Timer1->Interval=800*frequence;}
  173.     else
  174.     Timer1->Interval=200*frequence;
  175.   }
  176.   __finally
  177.   {
  178.     delete Registry;
  179.   }
  180.     //Find out if we are running under NT
  181.     if(Version!=0)
  182.     //Disable Ctrl-Alt-Del if appropriate.  NT handles password-protected
  183.     //screen savers at the system level, so this is only needed for non-NT
  184.     //situations with password protection enabled.
  185.     if(PWProtect&&Version>0x80000000)
  186.      SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, 0, 0);
  187.     //Copy a clone of the desktop onto the form, to
  188.     //serve as a background for the circle painting
  189.     //CopyScreen Me
  190.     //Make the cursor disappear
  191.     while (!ShowCursor(false)< -5); 
  192. }
  193. //---------------------------------------------------------------------------
  194. void __fastcall TMainForm::FormKeyDown(TObject *Sender, WORD &Key,
  195.       TShiftState Shift)
  196. {
  197. Close();
  198. }
  199. //---------------------------------------------------------------------------
  200. void __fastcall TMainForm::FormMouseDown(TObject *Sender,
  201.       TMouseButton Button, TShiftState Shift, int X, int Y)
  202. {
  203. Close();
  204. }
  205. //---------------------------------------------------------------------------
  206. void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
  207. {
  208. stoploop=true;
  209. stopcls=true;
  210. Timer1->Enabled =false;
  211. if (PWProtect && Version>0x80000000)
  212.       {
  213.         bool PassChck;
  214.         //We need a cursor so that the user can move around
  215.         //the password form
  216.         while(!ShowCursor(True) > 5);
  217.         typedef UINT(CALLBACK *FUN)(HWND);
  218.                    HINSTANCE hDll=LoadLibrary("password.cpl");
  219.                    FUN myfun;
  220.                    if(hDll!=NULL)
  221.                     {
  222.                      myfun=(FUN)GetProcAddress(hDll,"VerifyScreenSavePwd");
  223.                      if(!myfun)FreeLibrary(hDll);
  224.                      else
  225.                      PassChck=myfun(this->Handle);
  226.                     }
  227.         if(PassChck == false)
  228.           {
  229.             Timer1->Enabled =true;
  230.             //Make the cursor disappear again
  231.             while(!ShowCursor(False) < -5);
  232.             CanClose = false;
  233.             //stoploop=false;
  234.            }
  235.       }        
  236. }
  237. //---------------------------------------------------------------------------
  238. void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
  239. {
  240. while(!ShowCursor(True) > 5);
  241.   //re-enable Ctrl-Alt-Del if disabled
  242.     if(PWProtect&&Version>0x80000000)
  243.         SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, 0, 0);
  244. }
  245. //---------------------------------------------------------------------------
  246. void __fastcall TMainForm::FormMouseMove(TObject *Sender,
  247.       TShiftState Shift, int X, int Y)
  248. {
  249. static int MouseMoves=0;
  250.     MouseMoves = MouseMoves + 1;
  251.     if(MouseMoves >4)
  252.      {
  253.      this->Close();
  254.      MouseMoves = 0 ;
  255.      }
  256. }       
  257. //---------------------------------------------------------------------------
  258. void TMainForm::clsscreen(TImage * image)
  259. {
  260.   int style;
  261.   randomize();
  262.   style=random(5);
  263.   TColor color;
  264.   Timer1->Enabled=false;
  265.   if(bussy==false)
  266.   {
  267.   stopcls=false;
  268.   switch (style)
  269.   {
  270.     case 1:
  271.      bussy=true;
  272.      color=(TColor)RGB(rand()%256,rand()%256,rand()%256);
  273.        image->Canvas->Pen->Color=color;
  274.            image->Canvas->Brush->Color=color;
  275.      for(int i=0;i<=image->ClientWidth/2;i++)
  276.      {
  277.        if(stopcls) break;
  278.        Application->ProcessMessages();
  279.        image->Canvas->MoveTo(i,0);
  280.        image->Canvas->LineTo(i,image->ClientHeight);
  281.        image->Canvas->MoveTo(image->ClientWidth-i,0);
  282.        image->Canvas->LineTo(image->ClientWidth-i,image->ClientHeight);
  283.      }
  284.      break;
  285.     case 2:  //从中间到左右两边清屏
  286.      bussy=true;
  287.      color=(TColor)RGB(rand()%256,rand()%256,rand()%256);
  288.      image->Canvas->Pen->Color=color;
  289.      image->Canvas->Brush->Color=color;
  290.      for(int i=image->ClientWidth/2;i>=0;i--)
  291.      {
  292.       if(stopcls) break;
  293.       Application->ProcessMessages();
  294.        image->Canvas->MoveTo(i,0);
  295.        image->Canvas->LineTo(i,image->ClientHeight);
  296.        image->Canvas->MoveTo(image->ClientWidth-i,0);
  297.        image->Canvas->LineTo(image->ClientWidth-i,image->ClientHeight);
  298.      }
  299.      break;
  300.     case 3: //从上(顶)下(低)到中间清屏
  301.      bussy=true;
  302.       color=(TColor)RGB(rand()%256,rand()%256,rand()%256);
  303.       image->Canvas->Pen->Color=color;
  304.         image->Canvas->Brush->Color=color;
  305.      for(int i=0;i<=image->ClientHeight/2;i++)
  306.      {
  307.      if(stopcls) break;
  308.       Application->ProcessMessages();
  309.        image->Canvas->MoveTo(0,i);
  310.        image->Canvas->LineTo(image->ClientWidth,i);
  311.        image->Canvas->MoveTo(0,image->ClientHeight-i);
  312.        image->Canvas->LineTo(image->ClientWidth,image->ClientHeight-i);
  313.      }
  314.      break;
  315.     case 4: //从上(顶)下(低)到中间清屏
  316.      bussy=true;
  317.       color=(TColor)RGB(rand()%256,rand()%256,rand()%256);
  318.       image->Canvas->Pen->Color=color;
  319.       image->Canvas->Brush->Color=color;
  320.      for(int i=image->ClientHeight/2;i>=0;i++)
  321.      {
  322.      if(stopcls) break;
  323.       Application->ProcessMessages();
  324.        image->Canvas->MoveTo(0,i);
  325.        image->Canvas->LineTo(image->ClientWidth,i);
  326.        image->Canvas->MoveTo(0,image->ClientHeight-i);
  327.        image->Canvas->LineTo(image->ClientWidth,image->ClientHeight-i);
  328.      }
  329.      break;
  330.     default:  //菱形清屏,从四角向中心
  331.       bussy=true;
  332.        color=(TColor)RGB(rand()%256,rand()%256,rand()%256);
  333.        image->Canvas->Pen->Color=color;
  334.        image->Canvas->Brush->Color=color;
  335.        for(int i=0 ;i<image->ClientWidth;i+=30)
  336.         {
  337.           if(stopcls) break;
  338.            for(int j=0;j<=image->ClientHeight;j+=30*image->ClientHeight/image->ClientWidth)
  339.            {
  340.             if(stopcls) break;
  341.             Application->ProcessMessages();
  342.              image->Canvas->MoveTo(i,0);
  343.              image->Canvas->LineTo(0,j);
  344.              image->Canvas->MoveTo(image->ClientWidth-i,image->ClientHeight);
  345.              image->Canvas->LineTo(image->ClientWidth,image->ClientHeight-j);
  346.              image->Canvas->MoveTo(0,image->ClientHeight-j);
  347.              image->Canvas->LineTo(i,image->ClientHeight);
  348.              image->Canvas->MoveTo(image->ClientWidth-i,0);
  349.              image->Canvas->LineTo(image->ClientWidth,image->ClientHeight-j);
  350.            }
  351.           }
  352.    }
  353.   }
  354.   bussy=false;
  355.   Timer1->Enabled =true;
  356. }
  357. void __fastcall TMainForm::Image1MouseMove(TObject *Sender,
  358.       TShiftState Shift, int X, int Y)
  359. {
  360. static int MouseMoves=0;
  361.     MouseMoves = MouseMoves + 1;
  362.     if(MouseMoves >4)
  363.      {
  364.      this->Close();
  365.      MouseMoves = 0 ;
  366.      }        
  367. }
  368. //---------------------------------------------------------------------------
  369. void __fastcall TMainForm::Image1MouseDown(TObject *Sender,
  370.       TMouseButton Button, TShiftState Shift, int X, int Y)
  371. {
  372. Close();        
  373. }
  374. //---------------------------------------------------------------------------