Все можно сделать проще
| Код | type THComboBox=class(TComboBox) private HW:THintWindow; isShowHW:boolean; protected procedure WMCTLCOLORLISTBOX(var Message: TMessage);//message WM_CTLCOLORLISTBOX; procedure WndProc(var Message: TMessage); override; public constructor Create(AOwner: TComponent); override; destructor Destroy;override; end; implementation { THComboBox }
constructor THComboBox.Create(AOwner: TComponent); begin inherited; HW:=THintWindow.Create(self); HW.ActivateHint(rect(0,0,0,0),''); //Без этого, при первом показе, HW перекрывается выпадающим списком HW.ReleaseHandle; isShowHW:=false; end;
destructor THComboBox.Destroy; begin HW.Destroy; inherited; end;
procedure THComboBox.WMCTLCOLORLISTBOX(var Message: TMessage); var ItemIndex,txtlen:cardinal; twidth:cardinal; cr,pi:tpoint; txt:string; rct:TRECT; begin ItemIndex:=self.ItemIndex; if ItemIndex>=0 then begin txt:=self.Items[ItemIndex]; twidth:=self.Canvas.TextWidth(txt); GetWindowRect(self.Handle,rct); if twidth>(rct.Right-rct.Left) then begin pi.X:=rct.Left; pi.Y:=rct.Top; rct:=hw.CalcHintRect(1000,txt,nil); getcursorpos(cr); With rct do begin Left:=Left+pi.X; Right:=Left+Right; Top:=cr.Y+20; Bottom:=Top+Bottom; end; hw.ActivateHint(rct,txt); isShowHW:=true; exit; end; end; if isShowHW then begin hw.ReleaseHandle; isShowHW:=false; end; end;
procedure THComboBox.WndProc(var Message: TMessage); begin inherited; if Message.Msg=WM_CTLCOLORLISTBOX then WMCTLCOLORLISTBOX(Message)else if isShowHW then begin hw.ReleaseHandle; isShowHW:=false; end; end;
end.
|
|