画图闪烁
我在Paint消息里的画图,很闪,代码如下:
#include <math.h>
#pragma link "C:\\Program Files\\Borland\\CBuilder6\\Lib\\Psdk\\msimg32.lib"
void __fastcall TForm1::Button1Click(TObject *Sender)
{
#define bmw 500
#define bmh 500
static bool scan=false;
if(scan==true)
{
scan=false;
return;
}
scan=true;
int R;
if(bmw>bmh)
R=bmh>>1;
else
R=bmw>>1;
Graphics::TBitmap *bk=new Graphics::TBitmap();
Graphics::TBitmap *fk=new Graphics::TBitmap();
bk->Width=bmw;
bk->Height=bmh;
bk->Canvas->Brush->Color=0;
bk->Canvas->FillRect(Rect(0,0,bmw,bmh));
bk->Canvas->Pen->Color=0x4500;
for(int i=0;i<=bmw;i+=50)
{
bk->Canvas->MoveTo(0,i);
bk->Canvas->LineTo(bmw,i);
}
bk->Canvas->Pen->Color=0x6000;
for(int i=0;i<=bmh;i+=50)
{
bk->Canvas->MoveTo(i,0);
bk->Canvas->LineTo(i,bmh);
}
fk->Assign(bk);
fk->Canvas->Brush->Color=0xff;
BLENDFUNCTION m_bf={0,0,8,0};
fk->Canvas->Pen->Color=0x800000;
fk->Canvas->Pen->Width=2;
static float di=0;
static int mcx=0;
RECT Trect;
int Tr;
while(scan)
{
fk->Canvas->MoveTo(bmw>>1,bmh>>1);
fk->Canvas->LineTo((bmw>>1)-R*sin(di),(bmh>>1)-R*cos(di));
if(mcx++>60)
{
::AlphaBlend(fk->Canvas->Handle,0,0,bmw,bmh,bk->Canvas->Handle,0,0,bmw,bmh,m_bf);
mcx=0;
}
if(random(20)==10)
{
Tr=random(R>>1)+(R>>1)-16;
Trect.left=(bmw>>1)-Tr*sin(di-0.1);
Trect.top=(bmh>>1)-Tr*cos(di-0.1);
Trect.right=Trect.left+random(8)+1;
Trect.bottom=Trect.top+random(8)+1;
fk->Canvas->FillRect(Trect);
}
BitBlt(Canvas->Handle,10,10,bmw,bmh,fk->Canvas->Handle,0,0,SRCCOPY);
di+=0.001;
Application->ProcessMessages();
}
delete bk;
delete fk;
}
//---------------------------------------