两个位图不规则窗体,同一位置鼠标进出切换,不知道怎么实现,帮忙看看程序哪里出错,改改!!!
1、我制作了继承自TImage的组件TImage1,添加了OnMouseEnter,OnMouseExit事件,响应鼠标进出位图;
2、定义了void KouTu(TImage *Image1,TForm1 *Form)函数,制作图片不规则窗体;
3、我的程序如下:
TForm1 *Form1;
TImage1 *Image1,*Image2;
//---------------------------------------------------------------------------
void KouTu(TImage *Image1,TForm1 *Form)
{
Form->BorderStyle=bsNone;
register int x,y;
int L,r;
POINT *a;
bool Lb,rb;
HRGN WndRgn,TempRgn,tepRgn;
Image1->Left = 0;
Image1->Top = 0;
Image1->Width = Image1->Picture->Width+2;
Image1->Height = Image1->Picture->Height+2;
Form->Width=Image1->Picture->Width;
Form->Height=Image1->Picture->Height;
if ((a=(POINT*)malloc(Form1->Height*4*(sizeof(POINT))))==NULL)
{
ShowMessage("声请内存失败");
exit(0);
}
Form->Repaint();
//----------------------------------------------------------------------------
L=0;r=Image1->Height*2-1 ;
WndRgn=CreateRectRgn(0,0,Image1->Width ,Image1->Height );
//----------------------------------------------------------------------------
for (y=0;y<Image1->Height;y++)
{
Lb=true;
for (x=0;x<Image1->Width ;x++)
if(Image1->Canvas->Pixels[x][y]!=clWhite)
{
a[L].x=x;
a[L].y=y;
Lb=false;
break;
}
if(Lb)
a[L]=a[L-1];
L++;
//----------------------------------------------------------------------------
rb=true;
for(x=Image1->Width -1;x>=0;x--)
if(Image1->Canvas ->Pixels[x][y]!=clWhite)
{
a[r].x =x-1;
a[r].y=y;
rb=false;
break;
}
if(rb)
{
a[r]=a[r+1]; }
r--;
}
//---------------------------------------------------------------------------
r=Image1->Height * 2-1;
for(y=0;y<Image1->Height ;y++)
{
for(x=a[y].x;x<a[r].x ;x++)
if(Image1->Canvas ->Pixels[x][y]==clWhite)
{
tepRgn=CreateRectRgn(x,y,x+1,y+1);
CombineRgn(WndRgn,WndRgn,tepRgn,RGN_XOR);
DeleteObject(tepRgn);
}
r--;
}
//-----------------------------------------------------------
TempRgn=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE);
CombineRgn(WndRgn,WndRgn,TempRgn,RGN_AND);
DeleteObject(TempRgn);
free(a);
//---------------------------------------------------------
SetWindowRgn(Form->Handle,WndRgn,true);
SetWindowPos(Form->Handle,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
}
//------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Image1 = new TImage1(this);
Image2 = new TImage1(this);
Image1->Parent = this;
Image2->Parent = this;
Image1->OnMouseEnter = Image1MouseEnter;
Image2->OnMouseExit = Image2MouseExit;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseEnter(TObject *Sender)
{
KouTu(Image2,Form1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image2MouseExit(TObject *Sender)
{
KouTu(Image1,Form1);
}//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{ Image1->Picture->LoadFromFile("C:\\Documents and Settings\\Administrator.6CFADDBF0DBD4DD\\桌面\\080310074949718.bmp" );
Image2->Picture->LoadFromFile("C:\\Documents and Settings\\Administrator.6CFADDBF0DBD4DD\\桌面\\080310074949718_2.bmp" );
KouTu(Image1,Form1);
}
4、程序只能响应鼠标进入,无法响应鼠标离开,帮忙解决下问题!!!