9

我正在尝试创建一个 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;

显示了提示窗口,但我没有看到 TButton。提示窗口内似乎没有子窗口(我用 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;

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

对此有何反馈?

4

1 回答 1

10

不要问我为什么,但是你可以在旧版本的 Delphi 中通过在创建实例ParentWindow后立即将Application.HandleTHintWindow

HintWindow := THintWindow.Create(Self);
HintWindow.ParentWindow := Application.Handle;

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

于 2011-11-17T12:52:09.960 回答