Tips.37 C++Builder/Windowsプログラミング
ListView(vsReport)上でマウスのある位置の文字列を表示する


ListViewでマウスが指しているアイテム(サブアイテムも考慮して)のが隠れている場合、
Hintを使って表示する。
まず、ListViewのOnMouseMoveイベントを割り当てる。FormCreateで、
TApplication.OnShowHintイベントを割り当てる。

[ヘッダ]
class TForm1 : public TForm
{
...
private:
  TPoint TipPos;
public:
...
};

[ソース]
void __fastcall TForm1::ListView1MouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
    AnsiString ListTip = TListView_GetTooltipStr( ListView1, X, Y);
    TipPos = Point(X, Y);
    if ( ListTip.IsEmpty() )
    {
        ListView1->Hint = "";
        Application->CancelHint();
        return;
    }
    if ( ListView1->Hint == ListTip )
    {
        return;
    }
    ListView1->Hint = ListTip;
    Application->CancelHint();
}
void __fastcall TForm1::DoShowHint(System::AnsiString &HintStr, 
                                   bool &CanShow, THintInfo &HintInfo)
{
  if (HintInfo.HintControl == ListView1)
  {
    HintInfo.HintPos = TipPos;
    if ( ListView1->Hint.IsEmpty() )
    {
        CanShow = false;
    }
    else
    {
        CanShow = true;
    }
  }
}
//------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   //ヒントを表示する前のイベントハンドラを登録する。
   Application->OnShowHint = DoShowHint;
}
//------------------------------------------------------------------
戻る [参照] Tips36 TApplication OnShowHint TShowHintEvent