窗体动态特效集锦

类别:软件工程 点击:0 评论:0 推荐:

下面是头文件:
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
        TImage *Image1;
        TBitBtn *BitBtn1;
        TBitBtn *BitBtn2;
        TBitBtn *BitBtn3;
        TBitBtn *BitBtn4;
        TBitBtn *BitBtn5;
        TBitBtn *BitBtn6;
        TBitBtn *BitBtn7;
        TBitBtn *BitBtn8;
        TBitBtn *BitBtn9;
        TBitBtn *BitBtn10;
        TBitBtn *BitBtn11;
        TBitBtn *BitBtn12;
        TBitBtn *BitBtn13;
        TBitBtn *BitBtn14;
        TBitBtn *BitBtn15;
        TBitBtn *BitBtn16;
        TBitBtn *BitBtn17;
        TBitBtn *BitBtn18;
        TStaticText *StaticText1;
        TBitBtn *BitBtn19;
        TBitBtn *BitBtn20;
        TBitBtn *BitBtn21;
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall BitBtn1Click(TObject *Sender);
        void __fastcall BitBtn2Click(TObject *Sender);
        void __fastcall BitBtn3Click(TObject *Sender);
        void __fastcall BitBtn4Click(TObject *Sender);
        void __fastcall BitBtn5Click(TObject *Sender);
        void __fastcall BitBtn6Click(TObject *Sender);
        void __fastcall BitBtn7Click(TObject *Sender);
        void __fastcall BitBtn8Click(TObject *Sender);
        void __fastcall BitBtn9Click(TObject *Sender);
        void __fastcall BitBtn10Click(TObject *Sender);
        void __fastcall BitBtn11Click(TObject *Sender);
        void __fastcall BitBtn12Click(TObject *Sender);
        void __fastcall BitBtn13Click(TObject *Sender);
        void __fastcall BitBtn14Click(TObject *Sender);
        void __fastcall BitBtn15Click(TObject *Sender);
        void __fastcall BitBtn16Click(TObject *Sender);
        void __fastcall BitBtn17Click(TObject *Sender);
        void __fastcall BitBtn18Click(TObject *Sender);
        void __fastcall BitBtn19Click(TObject *Sender);
        void __fastcall BitBtn20Click(TObject *Sender);
        void __fastcall BitBtn21Click(TObject *Sender);
private:    // User declarations
        BITMAP bmp;
        HRGN MyRgn;
        Graphics::TBitmap *Bitmap1;
        int i,j;
        int WidthHalf;
        int HeightHalf;
        TRect Dest1,Source1,Dest2,Source2;
public:        // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

 

///////////////////////////////////////////////////////////////////////
下面是CPP文件

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "math.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::FormCreate(TObject *Sender)
{
        Form1->BorderStyle = bsNone;
        Form1->Left = 0;
        Form1->Top = 0;
        Form1->Width = Screen->Width;
        Form1->Height = Screen->Height;//窗体全屏显示

        Bitmap1 = new Graphics::TBitmap();//定义一个图象句柄//
        Bitmap1->LoadFromFile("test.bmp");//设定所要特效显示的图象为factory.bmp//
        if(GetDeviceCaps(Form1->Canvas->Handle,BITSPIXEL)==8){//取得显示窗口的颜色属性
                GetObject(Bitmap1->Handle,sizeof(BITMAP),(LPSTR)&bmp);
                if (bmp.bmBitsPixel==8){//如果特效显示的图象颜色属性为256色//
                        SelectPalette(Form1->Canvas->Handle,Bitmap1->Palette,FALSE);//从特效显示的颜色画板中提取配色方案//
                        RealizePalette(Form1->Canvas->Handle); //在显示窗口中设置配色方案//
                }
                Bitmap1->HandleType=bmDDB;
        }
}

//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{//图象从中间向左右拉开!
        Form1->Refresh();
        WidthHalf=Bitmap1->Width/2+Bitmap1->Width%2;
        for(i=0;i<=WidthHalf; i++){
                Dest1=Rect(WidthHalf-i,0,WidthHalf+i,Bitmap1->Height);
                Source1=Rect(WidthHalf-i,0,WidthHalf+i,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                for(j=0;j<10000;j++);//图像的延迟显示//
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{//图象由左右拉向中间!
        Form1->Refresh();
        WidthHalf=Bitmap1->Width/2+Bitmap1->Width%2;
        Form1->Refresh();
        for(i=0;i<=WidthHalf;i++){
                Source1=Dest1=Rect(0,0,i,Bitmap1->Height);
                Source2=Dest2=Rect(Bitmap1->Width-i,0,Bitmap1->Width,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                Form1->Canvas->CopyRect(Dest2,Bitmap1->Canvas,Source2);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{//图象从中间分到两边
        Form1->Refresh();
        HeightHalf=Bitmap1->Height/2+Bitmap1->Height%2;
        for(i=0;i<=HeightHalf;i++){
                Dest1=Rect(0,HeightHalf-i,Bitmap1->Width,HeightHalf);
                Source1=Rect(0,0,Bitmap1->Width,i);
                Dest2=Rect(0,HeightHalf,Bitmap1->Width,HeightHalf+i);
                Source2=Rect(0,Bitmap1->Height-i,Bitmap1->Width,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                Form1->Canvas->CopyRect(Dest2,Bitmap1->Canvas,Source2);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{//图象从两边靠拢
        Form1->Refresh();
        HeightHalf=Bitmap1->Height/2+Bitmap1->Height%2;
        for(i=0;i<=HeightHalf;i++){
                Dest1=Rect(0,0,Bitmap1->Width,i);
                Source1=Rect(0,HeightHalf-i,Bitmap1->Width,HeightHalf);
                Dest2=Rect(0,Bitmap1->Height-i,
                Bitmap1->Width,Bitmap1->Height);
                Source2=Rect(0,HeightHalf,Bitmap1->Width,HeightHalf+i);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                Form1->Canvas->CopyRect(Dest2,Bitmap1->Canvas,Source2);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn5Click(TObject *Sender)
{//图象从左拉向右
        Form1->Refresh();
        for(i=Bitmap1->Width;i>=0;i--){
                Dest1=Rect(0,0,Bitmap1->Width-i,Bitmap1->Height);
                Source1=Rect(i,0,Bitmap1->Width,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn6Click(TObject *Sender)
{//图象从右拉到左
        Form1->Refresh();
        for(i=0;i<=Bitmap1->Width;i++){
                Dest1=Rect(Bitmap1->Width-i,0,Bitmap1->Width,Bitmap1->Height);
                Source1=Rect(0,0,i,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn7Click(TObject *Sender)
{//图象从上拉到下
        Form1->Refresh();
        for(i=0;i<=Bitmap1->Height;i++){
                Dest1=Rect(0,0,Bitmap1->Width,i);
                Source1=Rect(0,Bitmap1->Height-i,Bitmap1->Width,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                for(j=0;j<1;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn8Click(TObject *Sender)
{//图象从下拉到上
        Form1->Refresh();
        for(i=0;i<=Bitmap1->Height;i++){
                Dest1 =Rect(0,Bitmap1->Height-i,Bitmap1->Width,
                Bitmap1->Height);
                Source1 =Rect(0,0,Bitmap1->Width,i);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn9Click(TObject *Sender)
{//图象从左现到右
        Form1->Refresh();
        for(i=0;i<=Bitmap1->Width;i++){
                Dest1 =Rect(0,0,i,Bitmap1->Height);
                Source1 =Rect(0,0,i,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn10Click(TObject *Sender)
{//图象从右现到左
        Form1->Refresh();
        for(i=Bitmap1->Width;i>=0;i--){
                Dest1 =Rect(i+0,0,0+Bitmap1->Width,0+Bitmap1->Height);
                Source1 =Rect(i,0,Bitmap1->Width,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn11Click(TObject *Sender)
{//图象从上现到下
        Form1->Refresh();
        for(i=0;i<=Bitmap1->Height;i++){
                Dest1 =Rect(0,0,Bitmap1->Width+0,i+0);
                Source1 =Rect(0,0,Bitmap1->Width,i);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn12Click(TObject *Sender)
{//图象从下现到上
        Form1->Refresh();
        for(i=Bitmap1->Height;i>=0;i--){
                Dest1=Rect(0,i+0,Bitmap1->Width+0,Bitmap1->Height+0);
                Source1=Rect(0,i,Bitmap1->Width,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn13Click(TObject *Sender)
{//金属熔铸A
        Form1->Refresh();
        for(i=Bitmap1->Height;i>=0;i--){
                Source1 =Rect(0,i,Bitmap1->Width,i+1);
                for(int j1=0;j1<=i;j1++){
                        Dest1 =Rect(0 ,j1,Bitmap1->Width+0,j1+1);
                        Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                        for(j=0;j<10000;j++);
                }
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn14Click(TObject *Sender)
{//逆金属熔铸
        Form1->Refresh();
        for(i=0;i<=Bitmap1->Height;i++){
                Source1 =Rect(0,i,Bitmap1->Width,i+1);
                for(int j1=Bitmap1->Height-1;j1>=i;j1--){
                        Dest1 =Rect(0,j1,Bitmap1->Width,j1+1);
                        Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                        for(j=0;j<10000;j++);
                }
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn15Click(TObject *Sender)
{
        Form1->Refresh();
        int j1=sqrt(Bitmap1->Width*Bitmap1->Width+
        Bitmap1->Height*Bitmap1->Height)/2+4;
        for (i=1;i<j1;i++){
                MyRgn=CreateEllipticRgn(Bitmap1->Width/2-i,
                Bitmap1->Height/2-i,
                Bitmap1->Width/2+i,
                Bitmap1->Height/2+i);
                SelectObject(Canvas->Handle,MyRgn);
                Canvas->Draw(0,0,Bitmap1);
                DeleteObject(MyRgn);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn16Click(TObject *Sender)
{
        Form1->Refresh();
        HeightHalf=Bitmap1->Height/2+Bitmap1->Height%2;
        Source1=Rect(0,0,Bitmap1->Width,HeightHalf);
        Source2=Rect(0,HeightHalf,Bitmap1->Width,Bitmap1->Height);
        for(i=0;i<=Bitmap1->Width;i++){
                Dest1=Rect(0-Bitmap1->Width+i,0,i,0+HeightHalf);
                Dest2=Rect(Bitmap1->Width-i,HeightHalf,Bitmap1->Width+Bitmap1->Width-i,Bitmap1->Height+0);
                Form1->Canvas->MoveTo(0-Bitmap1->Width+i-1,0);
                Form1->Canvas->LineTo(0-Bitmap1->Width+i-1,HeightHalf);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                Form1->Canvas->MoveTo(Bitmap1->Width+Bitmap1->Width-i,0);
                Form1->Canvas->LineTo(Bitmap1->Width+Bitmap1->Width-i,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest2,Bitmap1->Canvas,Source2);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn17Click(TObject *Sender)
{
        Form1->Refresh();
        WidthHalf=Bitmap1->Width/2+Bitmap1->Width%2;
        Source1=Rect(0,0,WidthHalf,Bitmap1->Height);
        Source2=Rect(WidthHalf,0,Bitmap1->Width,Bitmap1->Height);
        for(i=0;i<=Bitmap1->Height;i++){
                Dest1=Rect(0,0-Bitmap1->Height+i,WidthHalf,0+i);//Bitmap1->Width
                Dest2=Rect(WidthHalf,Bitmap1->Height-i,Bitmap1->Width,0+i);//Bitmap1->Height+1);
                Canvas->MoveTo(0,0-Bitmap1->Height+i-1);
                Form1->Canvas->LineTo(WidthHalf,0-Bitmap1->Height+i-1);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                Form1->Canvas->MoveTo(WidthHalf,
                Bitmap1->Height+Bitmap1->Height-i);
                Form1->Canvas->LineTo(Bitmap1->Width,
                Bitmap1->Height+Bitmap1->Height-i);
                Form1->Canvas->CopyRect(Dest2,Bitmap1->Canvas,Source2);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn18Click(TObject *Sender)
{
        Form1->Refresh();
        WidthHalf=Bitmap1->Width/2+Bitmap1->Width%2;
        Source1=Rect(0,0,WidthHalf,Bitmap1->Height);
        Source2=Rect(WidthHalf,0,Bitmap1->Width,Bitmap1->Height);
        for(i=0;i<=Bitmap1->Height;i++){
                Dest1=Rect(0,0-Bitmap1->Height+i,WidthHalf,0+i);//Bitmap1->Width
                Dest2=Rect(WidthHalf,Bitmap1->Height-i,Bitmap1->Width,i-0);
                Canvas->MoveTo(0,0-Bitmap1->Height+i-1);
                Form1->Canvas->LineTo(WidthHalf,0-Bitmap1->Height+i-1);
                Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
                Form1->Canvas->MoveTo(WidthHalf,
                Bitmap1->Height+Bitmap1->Height-i);
                Form1->Canvas->LineTo(Bitmap1->Width,
                Bitmap1->Height+Bitmap1->Height-i);
                Form1->Canvas->CopyRect(Dest2,Bitmap1->Canvas,Source2);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn19Click(TObject *Sender)
{
        Form1->Refresh();
        Source2=Rect(0,0,Bitmap1->Width,Bitmap1->Height);
        for(i=0;i<=Bitmap1->Height;i++){
                Dest2=Rect(0,Bitmap1->Height-i,Bitmap1->Width,i-0);
                Canvas->MoveTo(0,0-Bitmap1->Height+i-1);
                Form1->Canvas->MoveTo(0,Bitmap1->Height+Bitmap1->Height-i);
                Form1->Canvas->LineTo(Bitmap1->Width,Bitmap1->Height+Bitmap1->Height-i);
                Form1->Canvas->CopyRect(Dest2,Bitmap1->Canvas,Source2);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn20Click(TObject *Render)
{
        Form1->Refresh();
        Source2=Rect(0,Bitmap1->Height,Bitmap1->Width,0);
        for(i=0;i<=Bitmap1->Width;i++){
                Dest2=Rect(i-0,Bitmap1->Height,Bitmap1->Width-i,0);
                Canvas->MoveTo(0-Bitmap1->Width+i-1,0);
                Form1->Canvas->MoveTo(Bitmap1->Width+Bitmap1->Width-i,0);
                Form1->Canvas->LineTo(Bitmap1->Width+Bitmap1->Width-i,Bitmap1->Height);
                Form1->Canvas->CopyRect(Dest2,Bitmap1->Canvas,Source2);
                for(j=0;j<10000;j++);
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn21Click(TObject *Sender)
{
        Application->Terminate();
}
//---------------------------------------------------------------------------

本文地址:http://com.8s8s.com/it/it35259.htm