如何在THintWindow中创建TButton或其他控件?

kob*_*bik 9 delphi hint

我正在尝试创建一个THintWindow并在其上放置TButton或TFrame.这是我的代码:

TForm1 = class(TForm)
  Button1: TButton;
  Button2: TButton;
  procedure FormCreate(Sender: TObject);
  procedure Button1Click(Sender: TObject);
  procedure Button2Click(Sender: TObject);
private
  HintWindow: THintWindow;
public
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  HintWindow := THintWindow.Create(Self);
  HintWindow.Color := clInfoBk;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  P: TPoint;
  R: TRect;
  Control: TControl;
begin
  Control := Button1;
  P := Control.ClientToScreen(Point(0, Control.Height));
  R := Rect(P.X, P.Y, P.x + 100, P.Y + 100);
  with TButton.Create(HintWindow) do
  begin
    Parent := HintWindow;
    Caption := 'My Button';
  end;
  HintWindow.ActivateHint(R, 'My Hint');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  HintWindow.ReleaseHandle;
end;
Run Code Online (Sandbox Code Playgroud)

显示提示窗口,但我没有看到TButton.看来Hint窗口里面没有子窗口(我用Spy ++测试了"第一个孩子").我还试图用新的CreateParams子类化THintWindow,即:

procedure TMyHintWindow.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.Style := Params.Style or WS_CLIPCHILDREN;
  Params.ExStyle := Params.ExStyle or WS_EX_CONTROLPARENT;
end;
Run Code Online (Sandbox Code Playgroud)

当我在提示窗口中创建一个TFrame作为子项时,Spy ++显示提示窗口上有一个子项但我看不到它(即使我强制它可见).

对此有任何反馈吗?

Dav*_*nan 10

不要问我为什么,但是你可以通过在创建实例后立即将ParentWindowto 设置为旧版本的Delphi来使其工作:Application.HandleTHintWindow

HintWindow := THintWindow.Create(Self);
HintWindow.ParentWindow := Application.Handle;
Run Code Online (Sandbox Code Playgroud)

这个答案的灵感来自现代版本的Delphi VCL源代码.