Title: HintWindows with Icons
Question: Is it possible to draw icons on hint windows?
Answer:
Below is the code for a Delphi unit for putting the application main icon on hint windows:
{--beginning of code--}
unit HintX;
interface
uses
Windows, Messages, Controls;
type
TIconHintX = class(THintWindow)
protected
procedure Paint; override;
public
function CalcHintRect(MaxWidth: Integer; const AHint: string; AData: Pointer): TRect; override;
end;
implementation
uses Forms;
{ TIconHintX }
{-Calculate the new size of the hint window to support an icon:-}
function TIconHintX.CalcHintRect(MaxWidth: Integer; const AHint: string;
AData: Pointer): TRect;
begin
Result := inherited CalcHintRect(MaxWidth, AHint, AData); Result.Right := (Length(AHint) * 5) + Application.Icon.Width;
Result.Bottom := (Application.Icon.Height) * 2;
end;
procedure TIconHintX.Paint;
const
MARGIN = 5;
begin
inherited;
Canvas.Draw(MARGIN, MARGIN * 5, Application.Icon);
SendMessage(Handle, WM_NCPAINT, 0, 0); //hint window border paint
end;
initialization
//this assigns our new class as the dafault hint window class:
HintWindowClass := TIconHintX;
end.
{--end of code--}
To see this in action, all you have to do is include the unit in your app's USES list