지금 님께서 정확히 무엇을 만들고자 하시는지 잘모르겠네요
TImage를 랩핑하여 클래스를 만들겠다면
아래와 같은 식으로 이벤트를 처리하면 될듯 합니다.
class MyImage
{
private:
TImage *pImage;
AnsiString strImageName;
TMouseEvent FOnMouseDown;
TMouseMoveEvent FOnMouseMove;
TMouseEvent FOnMouseUp;
private:
void __fastcall ImgMouseDown(TObject *Sender,TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall ImgMouseMove(TObject *Sender, TShiftState Shift,int X, int Y);
void __fastcall ImgMouseUp(TObject *Sender,TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall SetImageFileName(String sFileName);
public:
MyImage(TWinControl *Parent);
~MyImage();
public:
__property String ImageFileName = {read=strImageName,write=SetImageFileName};
__property TMouseEvent OnMouseDown = {read=FOnMouseDown, write=FOnMouseDown};
__property TMouseMoveEvent OnMouseMove = {read=FOnMouseMove, write=FOnMouseMove};
__property TMouseEvent OnMouseUp = {read=FOnMouseUp, write=FOnMouseUp};
};
위와같이 MyImage 내부에 TImage 이벤트 핸들러 함수를 만들어 두시구요
다시 그 이벤트를 밖으로 노출시키려면 __Propery 만들어야 됩니다
MyImage::MyImage(TWinControl *Parent)
{
FOnMouseDown=NULL;
FOnMouseMove=NULL;
FOnMouseUp=NULL;
pImage = new TImage(Parent);
pImage->Parent = Parent;
pImage->OnMouseDown = ImgMouseDown;
pImage->OnMouseMove = ImgMouseMove;
pImage->OnMouseUp = ImgMouseUp;
}
MyImage::~MyImage() {
delete pImage;
}
void __fastcall MyImage::SetImageFileName(String sFileName)
{
strImageName=sFileName;
if(FileExists(strImageName))
{
pImage->Picture->Bitmap->LoadFromFile(strImageName);
pImage->Width = pImage->Picture->Bitmap->Width;
pImage->Height = pImage->Picture->Bitmap->Height;
}
}
void __fastcall MyImage::ImgMouseDown(TObject *Sender,TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(FOnMouseDown)
FOnMouseDown(Sender,Button,Shift,X,Y);
}
void __fastcall MyImage::ImgMouseMove(TObject *Sender, TShiftState Shift,int X, int Y)
{
if(FOnMouseMove)
FOnMouseMove(Sender,Shift,X,Y);
//이미지 에니메이션 관련 코드?
}
void __fastcall MyImage::ImgMouseUp(TObject *Sender,TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(FOnMouseUp)
FOnMouseUp(Sender,Button,Shift,X,Y);
}
아래는 위 MyImage 사용 예 입니다.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
MyImage *Img=new MyImage(Panel1);
Img->ImageFileName="C:\\Test.bmp";
Img->OnMouseMove = Image1MouseMove;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
Label1->Caption="( "+IntToStr(X)+" , "+IntToStr(Y)+" )";
}
VCL(Delphi 또는 C++Builder)의 Component 들은 대게 위와같은 식으로 Event들이 만들어져 있습니다.
그럼..
있는그대로 님이 쓰신 글 :
: 패널 위에 이미지 만들어서 올리고 마우스오버시 스트링 출력시키려고 합니다.
: ----------------------------------------------------------------------------
: class MyImage
: {
: public:
: AnsiString strImageName;
: TImage *pImage;
:
: MyImage(TPanel *pParent) {
: pImage = new TImage(pParent);
: pImage->Parent = pParent;
: pImage->OnMouseMove = pParent->OnMouseMove;
:
: }
:
: ~MyImage() {
: delete pImage;
: }
: };
: ----------------------------------------------------------------------------
: 이 정도로 pParent에 strImageName를 넘겨주면 되겠지 생각했는데, 막상 하려니 방법을 모르겠네요.
: 조언 부탁드립니다.