C++ Builder
| Главная | Уроки | Статьи | FAQ | Форум | Downloads | Литература | Ссылки | RXLib | Диски |

 
Картинка в... ...Хинте??
.piero
Отправлено: 25.06.2004, 16:05


Дежурный стрелочник

Группа: Участник
Сообщений: 62



Такое реально, и если реально, то как???
Ну очень надо...
MDM
Отправлено: 28.06.2004, 08:15


Ученик-кочегар

Группа: Участник
Сообщений: 23



QUOTE (.piero @ 25/06/2004, 17:07)
Такое реально, и если реально, то как???
Ну очень надо...

//ImageHintWindow.h
class TImageHintWindow : public THintWindow
{
__published:
__property TImage* Image = {
read = Image_, write = Image_
};
private:
TImage* Image_;
public:
__fastcall TImageHintWindow(TComponent* Owner);
virtual TRect __fastcall CalcHintRect(int MaxWidth, const AnsiString AHint,
void* AData);
};

//ImageHintWindow..cpp
__fastcall TImageHintWindow::TImageHintWindow(TComponent* Owner)
: THintWindow(Owner)
{
Image_ = new TImage(this);
Image_->Parent = this;
Image_->AutoSize = true;
Image_->Left = 1;
Image_->Top = 1;
Image_->Enabled = false;
}
TRect __fastcall TImageHintWindow::CalcHintRect(int MaxWidth, const AnsiString AHint, void* AData)
{
TRect HintRect = Image_->ClientRect;
HintRect.Right += 4;
return HintRect;
}

//Unit1.h
...
#include "Unit1.h"
...
class TForm1 : public TForm
{
__published:
TTreeView *TreeView1;
TImageList *ImageList1;
TImageList *HintImageList;
TTimer *Timer1;
void __fastcall TreeView1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
void __fastcall TreeView1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall Timer1Timer(TObject *Sender);
private:
TTreeNode* last_node_;
unsigned char tic_;
TImageHintWindow* HintWindow_;
protected:
virtual void __fastcall DoActivateHint(
const TPoint& P);
virtual void __fastcall DoHideHint();

public:
__fastcall TForm1(TComponent* Owner);
const static unsigned char MAXTIC = 10;
};
extern PACKAGE TForm1 *Form1;

//ImageHintWindow.cpp
__fastcall TForm1::TForm1(
TComponent* Owner) : TForm(Owner),
last_node_(NULL)
{
HintWindow_ = new TImageHintWindow(this);
HintWindow_->Brush->Color = clWindow;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DoActivateHint(
const TPoint& P)
{
TRect HintRect = HintWindow_->CalcHintRect(0, NULL, NULL);
OffsetRect(static_cast(&HintRect), P.x + 10, P.y + 10);
HintWindow_->ActivateHint(HintRect, NULL);
tic_ = 0;
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DoHideHint()
{
const HWND hHint = HintWindow_->Handle;
const bool showing = IsWindowVisible(hHint);
if (showing)
{
ShowWindow(hHint, SW_HIDE);
Timer1->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::
TreeView1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
TTreeNode* current_node = TreeView1->GetNodeAt(X, Y);
if (current_node && current_node != last_node_ && current_node->Level == 0)
{
HintImageList->GetBitmap(
current_node->Index,
HintWindow_->Image->Picture->Bitmap
);
DoActivateHint(TreeView1->
ClientToScreen(Point(X, Y))
);
}
else if (!current_node ||
current_node->Level> 0)
{
DoHideHint();
}
last_node_ = current_node;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::
TreeView1MouseDown(TObject *Sender,
TMouseButton Button,
TShiftState Shift, int X, int Y)
{
DoHideHint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::
Timer1Timer(TObject *Sender)
{
if (++tic_> MAXTIC)
{
DoHideHint();
}
else
{
POINT PMouse = {0};
GetCursorPos(&PMouse);
RECT RTreeView = {0};
GetWindowRect(TreeView1->Handle, &RTreeView);
if (!PtInRect(&RTreeView, PMouse))
{
last_node_ = NULL;
DoHideHint();
}
}
}

Вернуться в Вопросы программирования в C++Builder