Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:3k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. __fastcall TForm1::TForm1(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TForm1::Button1Click(TObject *Sender)
  16. {
  17.   TRect rc;
  18.   rc.Left=0;
  19.   rc.Right=Image1->Width;
  20.   rc.Top=0;
  21.   rc.Bottom=Image1->Height;
  22.   Image1->Canvas->CopyMode=cmSrcPaint;
  23.   Image1->Canvas->CopyRect(rc,Image2->Canvas,rc);
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TForm1::Button2Click(TObject *Sender)
  27. {
  28.   TRect rc;
  29.   Image3->Width=Image1->Width;
  30.   Image3->Height=Image1->Height;
  31.   rc.Left=0;
  32.   rc.Right=Image1->Width;
  33.   rc.Top=0;
  34.   rc.Bottom=Image1->Height;
  35.   Image3->Canvas->CopyMode=cmSrcCopy;
  36.   Image3->Canvas->CopyRect(rc,Image1->Canvas,rc);
  37.   Image1->Canvas->Brush->Color=clWhite;
  38.   Image1->Canvas->FillRect(rc);
  39.   ID=0;
  40.   Timer1->Enabled=True;
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TForm1::PaintBlocks(int xbg,int ybg)
  44. {
  45.   TRect rc;
  46.   int CurX,CurY,xnn,ynn;
  47.   xnn=Image1->Width/10+1;
  48.   ynn=Image1->Height/10+1;
  49.   for(CurX=xbg;CurX<xnn;CurX+=2)
  50.     for(CurY=ybg;CurY<ynn;CurY+=2)
  51.     {
  52.       rc.Left=CurX*10;
  53.       rc.Right=rc.Left+10;
  54.       rc.Top=CurY*10;
  55.       rc.Bottom=rc.Top+10;
  56.       Image1->Canvas->CopyMode=cmSrcCopy;
  57.       Image1->Canvas->CopyRect(rc,Image3->Canvas,rc);
  58.     }
  59. }
  60. //---------------------------------------------------------------------------
  61. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  62. {
  63.   if(ID==0)
  64.   {
  65.     PaintBlocks(0,0);
  66.   }
  67.   else if(ID==1)
  68.   {
  69.     PaintBlocks(1,1);
  70.   }
  71.   else if(ID==2)
  72.   {
  73.     PaintBlocks(1,0);
  74.   }
  75.   else
  76.   {
  77.     PaintBlocks(0,1);
  78.     Timer1->Enabled=False;
  79.   }
  80.   ID++;
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TForm1::Button3Click(TObject *Sender)
  84. {
  85.   TRect rc;
  86.   rc.Left=0;
  87.   rc.Right=Image1->Width;
  88.   rc.Top=0;
  89.   rc.Bottom=Image1->Height;
  90.   Image1->Canvas->CopyMode=cmSrcPaint;
  91.   Image1->Canvas->CopyRect(rc,Image2->Canvas,rc);
  92.   Image4->Canvas->CopyMode=cmMergePaint;
  93.   Image4->Canvas->CopyRect(rc,Image2->Canvas,rc);
  94.   Image1->Canvas->CopyMode=cmSrcAnd;
  95.   Image1->Canvas->CopyRect(rc,Image4->Canvas,rc);
  96. }
  97. //---------------------------------------------------------------------------