两个位图不规则窗体,同一位置鼠标进出切换,不知道怎么实现,帮忙看看程序哪里出错,改改!!!

wangming24 2009-04-13 12:22:35
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、程序只能响应鼠标进入,无法响应鼠标离开,帮忙解决下问题!!!
...全文
129 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
shejirenshenga 2011-07-12
  • 打赏
  • 举报
回复
121759184加入设计人生 一起前进
wangming24 2009-04-13
  • 打赏
  • 举报
回复
Image1MouseUp是松开鼠标促发的事件,我需求的是鼠标离开图片促发事件.
wangming24 2009-04-13
  • 打赏
  • 举报
回复
在位图不规则窗体上单击后,移出窗体后,切换图片功能就消失了,因此加上以下程序:

void __fastcall TForm1::Image2MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
SetCaptureControl(Image2);
}
我来看看CB 2009-04-13
  • 打赏
  • 举报
回复
应该是利用的鼠标消息不对

void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y)

试试
wangming24 2009-04-13
  • 打赏
  • 举报
回复
改下:
void __fastcall TForm1::Image1MouseEnter(TObject *Sender)
{

Image2->Visible = true;
Image1->Visible = false;
if(state==false)
{
KouTu(Image2,Form1);
state==true;
}
SetCaptureControl(Image2);
}
wangming24 2009-04-13
  • 打赏
  • 举报
回复
改了下,可以了,程序如下:
TForm1 *Form1;
TImage1 *Image1,*Image2;
static bool state;

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

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)
{

Image2->Visible = true;
Image1->Visible = true;
if(state==false)
{
KouTu(Image2,Form1);
state==true;
}
SetCaptureControl(Image2);
}
//----------------------------------------------------------
void __fastcall TForm1::Image2MouseExit(TObject *Sender)
{

Image1->Visible =true;
Image2->Visible =false;
ReleaseCapture () ;

}

//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{

Image1->Picture->LoadFromFile("C:\\Documents andSettings\\Administrator.6CFADDBF0DBD4DD\\桌
面\\080310074949718.bmp" );
Image2->Picture->LoadFromFile("C:\\Documents and Settings\\Administrator.6CFADDBF0DBD4DD\\桌面\\080310074949718_2.bmp" );
KouTu(Image1,Form1);

}

13,870

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧