可以编译通过,但执行不了,现把代码全部贴出:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end; TMyHintWindow=class(THintWindow)
private
FActivating:Boolean;
FHDirection:Boolean;
FVDirection:Boolean;
procedure WMEraseBkgnd(var Message:
TWmEraseBkgnd);message WM_ERASEBKGND;
protected
procedure paint;override;
public
constructor Create(AOwner:TComponent);override;
procedure ActiveHint(Rect:TRect;const AHint:string);
function CalcHintRect(MaxWidth:Integer;const AHint:string;AData:Pointer):TRect;override;
end;var
Form1: TForm1;implementation{$R *.dfm}
constructor TMyHintWindow.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
Color:=$80FFFF;
canvas.Font.Size:=14;
end;procedure TMyHintWindow.WMEraseBkgnd(var Message: TWmEraseBkgnd);
begin
Message.Result:=1;
end;procedure TMyHintWindow.paint;
Var
R,ArrowR,TextR:TRect;
RectRgn,TPolyRgn,ShadowRgn:HRgn;
AP:array[0..2] of TPoint;begin
R:=ClientRect;
Inc(R.Left,2);
Inc(R.Top,2);
canvas.Font.Color:=clInfoText;
canvas.Brush.Color:=$80FFFF;
TextR:=R;
ArrowR:=R;
if Fvdirection then
begin
Inc(textR.Top,22);
arrowR.Bottom:=textR.Top;
end
else
begin
arrowR.Top:=arrowR.Bottom-22;
textR.Bottom:=arrowR.Top;
end;
if Fhdirection then
begin
if Fvdirection then
begin
AP[0]:=arrowr.TopLeft;
AP[1].X:=arrowR.Left+10;
AP[2].X:=Arrowr.Left+25;
AP[1].Y:=arrowr.Bottom;
AP[2].Y:=arrowr.Bottom;
end
else
begin
AP[0].X:=arrowr.Left;
AP[0].Y:=arrowr.Bottom;
AP[1].X:=arrowR.Left+10;
AP[2].X:=Arrowr.Left+25;
AP[1].Y:=arrowr.top;
AP[2].Y:=arrowr.top;
end;
end
else
begin
if Fvdirection then
begin
AP[0].X:=arrowr.Right;
AP[0].Y:=arrowr.top;
AP[1].X:=arrowR.Right-10;
AP[2].X:=Arrowr.Right-25;
AP[1].Y:=arrowr.bottom;
AP[2].Y:=arrowr.bottom;
end
else
begin
AP[0]:=arrowr.bottomRight;
AP[1].X:=arrowR.Right-10;
AP[2].X:=Arrowr.Right-25;
AP[1].Y:=arrowr.top;
AP[2].Y:=arrowr.top;
end;
end;
RectRgn:=CreateRoundRectRgn(TextR.Left,textr.Top,textr.Right,textr.Bottom,10,10);
TPolyRgn:=CreatePolygonRgn(AP,3,WINDING);
CombineRgn(RectRgn,RectRgn,TPolyRgn,RGN_OR);FillRgn(canvas.Handle,RectRgn,canvas.Brush.Handle);
DeleteObject(RectRgn);
DeleteObject(TPolyRgn);DrawText(canvas.Handle,PChar(Caption),-1,TextR,DT_VCENTER OR DT_CENTER OR DT_NOPREFIX OR DT_WORDBREAK );
end;procedure TMyHintWindow.ActiveHint(Rect:TRect;const AHint:string);
beginFhdirection:=True;
Fvdirection:=True;
Factivating:=True;
try
Caption:=AHint;
Inc(Rect.Bottom,4);
UpdateboundsRect(Rect);if Rect.Left<Screen.DesktopLeft then
begin
rect.Left:=screen.DesktopLeft;
end;
if rect.Top+Height>screen.DesktopHeight then
begin
dec(rect.Top,Height);
Fvdirection:=false;
end;
if rect.Left+width>screen.DesktopWidth then
begin
dec(rect.Left,Width);
Fhdirection:=false;
end;
if rect.Bottom<screen.DesktopTop then
begin
rect.Bottom:=screen.DesktopTop;
Fvdirection:=false;
end;setwindowpos(handle,HWND_TOPMOST,rect.Left,rect.Top,Width,Height,SWP_SHOWWINDOW OR SWP_NOACTIVATE);
Invalidate;
finally
Factivating:=false;
end;
end;function TMyHintWindow.CalcHintRect(MaxWidth:Integer;const AHint:string;AData:Pointer):TRect;
begin
Result:=Rect(0,0,canvas.TextWidth(AHint) ,canvas.TextHeight(AHint));
Inc(result.Right,22);
inc(result.Bottom,10);
dec(result.Top,15); Setwindowpos(handle,HWND_TOPMOST,result.Left,result.Top,Width,Height,SWP_HIDEWINDOW OR SWP_NOACTIVATE);
Invalidate;
end;initialization
HintWindowClass:=TMyHintWindow;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end; TMyHintWindow=class(THintWindow)
private
FActivating:Boolean;
FHDirection:Boolean;
FVDirection:Boolean;
procedure WMEraseBkgnd(var Message:
TWmEraseBkgnd);message WM_ERASEBKGND;
protected
procedure paint;override;
public
constructor Create(AOwner:TComponent);override;
procedure ActiveHint(Rect:TRect;const AHint:string);
function CalcHintRect(MaxWidth:Integer;const AHint:string;AData:Pointer):TRect;override;
end;var
Form1: TForm1;implementation{$R *.dfm}
constructor TMyHintWindow.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
Color:=$80FFFF;
canvas.Font.Size:=14;
end;procedure TMyHintWindow.WMEraseBkgnd(var Message: TWmEraseBkgnd);
begin
Message.Result:=1;
end;procedure TMyHintWindow.paint;
Var
R,ArrowR,TextR:TRect;
RectRgn,TPolyRgn,ShadowRgn:HRgn;
AP:array[0..2] of TPoint;begin
R:=ClientRect;
Inc(R.Left,2);
Inc(R.Top,2);
canvas.Font.Color:=clInfoText;
canvas.Brush.Color:=$80FFFF;
TextR:=R;
ArrowR:=R;
if Fvdirection then
begin
Inc(textR.Top,22);
arrowR.Bottom:=textR.Top;
end
else
begin
arrowR.Top:=arrowR.Bottom-22;
textR.Bottom:=arrowR.Top;
end;
if Fhdirection then
begin
if Fvdirection then
begin
AP[0]:=arrowr.TopLeft;
AP[1].X:=arrowR.Left+10;
AP[2].X:=Arrowr.Left+25;
AP[1].Y:=arrowr.Bottom;
AP[2].Y:=arrowr.Bottom;
end
else
begin
AP[0].X:=arrowr.Left;
AP[0].Y:=arrowr.Bottom;
AP[1].X:=arrowR.Left+10;
AP[2].X:=Arrowr.Left+25;
AP[1].Y:=arrowr.top;
AP[2].Y:=arrowr.top;
end;
end
else
begin
if Fvdirection then
begin
AP[0].X:=arrowr.Right;
AP[0].Y:=arrowr.top;
AP[1].X:=arrowR.Right-10;
AP[2].X:=Arrowr.Right-25;
AP[1].Y:=arrowr.bottom;
AP[2].Y:=arrowr.bottom;
end
else
begin
AP[0]:=arrowr.bottomRight;
AP[1].X:=arrowR.Right-10;
AP[2].X:=Arrowr.Right-25;
AP[1].Y:=arrowr.top;
AP[2].Y:=arrowr.top;
end;
end;
RectRgn:=CreateRoundRectRgn(TextR.Left,textr.Top,textr.Right,textr.Bottom,10,10);
TPolyRgn:=CreatePolygonRgn(AP,3,WINDING);
CombineRgn(RectRgn,RectRgn,TPolyRgn,RGN_OR);FillRgn(canvas.Handle,RectRgn,canvas.Brush.Handle);
DeleteObject(RectRgn);
DeleteObject(TPolyRgn);DrawText(canvas.Handle,PChar(Caption),-1,TextR,DT_VCENTER OR DT_CENTER OR DT_NOPREFIX OR DT_WORDBREAK );
end;procedure TMyHintWindow.ActiveHint(Rect:TRect;const AHint:string);
beginFhdirection:=True;
Fvdirection:=True;
Factivating:=True;
try
Caption:=AHint;
Inc(Rect.Bottom,4);
UpdateboundsRect(Rect);if Rect.Left<Screen.DesktopLeft then
begin
rect.Left:=screen.DesktopLeft;
end;
if rect.Top+Height>screen.DesktopHeight then
begin
dec(rect.Top,Height);
Fvdirection:=false;
end;
if rect.Left+width>screen.DesktopWidth then
begin
dec(rect.Left,Width);
Fhdirection:=false;
end;
if rect.Bottom<screen.DesktopTop then
begin
rect.Bottom:=screen.DesktopTop;
Fvdirection:=false;
end;setwindowpos(handle,HWND_TOPMOST,rect.Left,rect.Top,Width,Height,SWP_SHOWWINDOW OR SWP_NOACTIVATE);
Invalidate;
finally
Factivating:=false;
end;
end;function TMyHintWindow.CalcHintRect(MaxWidth:Integer;const AHint:string;AData:Pointer):TRect;
begin
Result:=Rect(0,0,canvas.TextWidth(AHint) ,canvas.TextHeight(AHint));
Inc(result.Right,22);
inc(result.Bottom,10);
dec(result.Top,15); Setwindowpos(handle,HWND_TOPMOST,result.Left,result.Top,Width,Height,SWP_HIDEWINDOW OR SWP_NOACTIVATE);
Invalidate;
end;initialization
HintWindowClass:=TMyHintWindow;
Delphi的Hint(2)
http://blog.csdn.net/linzhengqun