控件的内容如下:
__fastcall TFSImageButton::TFSImageButton(TComponent* Owner)
: TImage(Owner)
{
OldProc = WindowProc;
WindowProc = NewProc;
_FPictureOver = new TPicture();
_FPictureDown = new TPicture();
_FPictureIdle = new TPicture();
_FPictureDis = new TPicture();
_FPictureOver->OnChange = PictureChanged;
_FPictureDown->OnChange = PictureChanged;
_FPictureIdle->OnChange = PictureChanged;
_FPictureDis->OnChange = PictureChanged;
_Down = false; //-- 鼠标按下判断
_FEnter = false; //-- 鼠标进入判断
Cursor = crHandPoint;
}
//---------------------------------------------------------------------------
void __fastcall TFSImageButton::NewProc(TMessage& Message)
{
if(Message.Msg == CM_MOUSEENTER) //-- WM_MOUSEMOVE
{//-- 进入时
if( _FEnter == true ) return; //-- 如果已经进入就退出
_FEnter = true;
DrawPicture();
}
else if(Message.Msg == CM_MOUSELEAVE) //-- WM_MOUSELEAVE
{//-- 离开时
if( _FEnter == false ) return; //-- 如果已经离开就退出
_FEnter = false;
DrawPicture();
}
else if(Message.Msg == WM_LBUTTONUP)
{//-- 弹起时
_Down = false;
DrawPicture();
}
else if(Message.Msg == WM_LBUTTONDOWN)
{//-- 按下时
_Down = true;
DrawPicture();
}
OldProc(Message);
}
//---------------------------------------------------------------------------
void __fastcall TFSImageButton::DrawPicture(void) //-- 画图
{
//TRect MyRect; //-- 按钮的面积范围
TPicture *tmpPicture;
if ( _FEnter && !_Down ) //-- 鼠标进入时
{
tmpPicture = _FPictureOver;
BringToFront();
}
else if( _Down && _FEnter ) //-- 鼠标按下时
{
tmpPicture = _FPictureDown;
}
else if( (!_Down && !_FEnter) || !_FEnter ) //-- 鼠标离开时
{
tmpPicture = _FPictureIdle;
}
if( tmpPicture->Graphic == NULL ) //--如果没有图的时候
{
if( _FPictureOver->Graphic != NULL )
{
Width = _FPictureOver->Width;
Height = _FPictureOver->Height;
}
Picture->Graphic = NULL;
return;
}
Width = tmpPicture->Graphic->Width;
Height = tmpPicture->Graphic->Height;
Picture = tmpPicture;
}
//---------------------------------------------------------------------------
现在的问题是很闪,具体文件下载(因为没有办法上传)
谢谢!
--------------------next---------------------
阅读(1091) | 评论(0) | 转发(0) |