我应该如何为非可视 VCL 组件提供内部私有非可视窗口(句柄)?

发布于 2024-12-26 09:41:46 字数 1974 浏览 1 评论 0原文

这是一个后续问题。

我之前的问题:

我的问题:

TComponent 不拥有窗口句柄像TWinControl。我不想依赖外部的。

这是我的自定义组件的一个片段

type
  TMyClipBoardListener = class(TComponent)
  private
    FInnerWindowHandle: HWnd;
    FNextHWnd:  HWnd;
    //...
  protected
    procedure Loaded; override;
    procedure WndProc(var Msg: TMessage); // <<< This is my wouldbe Window to handle messages
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    // ...
  published
    // ...
  end;

我的自定义组件的实现摘录

constructor TMyClipBoardListener .Create(AOwner: TComponent);
begin
  inherited;
  //
  FInnerWindowHandle := ...; // <<< What to do here ? Should I pass it to a function/procedure I missed?
end;

destructor TMyClipBoardListener .Destroy;
begin
  if not(csDesigning in ComponentState) then
  begin
    ChangeClipboardChain(FInnerWindowHandle, FNextHWnd);
  end;
  //
  // <<< Are there some cleaning code related to FInnerWindowHandle to implement here or elsewhereCreates a window that implements a specified window procedure. ?
  //
  inherited;
end;

procedure TMyClipBoardListener.Loaded;
begin
  inherited;
  //
  if not(csDesigning in ComponentState) then
  begin
    FNextHWnd:= SetClipboardViewer(FInnerWindowHandle);
  end;
end;

procedure TMyClipBoardListener.WndProc(var Msg: TMessage);
begin
  with Msg do
  begin
    // Message to handle : WM_CHANGECBCHAIN and WM_DRAWCLIPBOARD
    // ... 
    else
      Result := DefWindowProc(FInnerWindowHandle, Msg, WParam, LParam); // <<< Is this the right way to do default handling properly?
  end;
end;

我的问题:

我怎样才能为我的自定义组件获取一个实现嵌入式窗口过程的内部窗口?

This is a follow-up question.

My prior questions:

My problem:

TComponent doesn't own a window handle like TWinControl. I don't want to rely on an external one.

This is a snippet of my custom component

type
  TMyClipBoardListener = class(TComponent)
  private
    FInnerWindowHandle: HWnd;
    FNextHWnd:  HWnd;
    //...
  protected
    procedure Loaded; override;
    procedure WndProc(var Msg: TMessage); // <<< This is my wouldbe Window to handle messages
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    // ...
  published
    // ...
  end;

Implementation excerpt of my custom component

constructor TMyClipBoardListener .Create(AOwner: TComponent);
begin
  inherited;
  //
  FInnerWindowHandle := ...; // <<< What to do here ? Should I pass it to a function/procedure I missed?
end;

destructor TMyClipBoardListener .Destroy;
begin
  if not(csDesigning in ComponentState) then
  begin
    ChangeClipboardChain(FInnerWindowHandle, FNextHWnd);
  end;
  //
  // <<< Are there some cleaning code related to FInnerWindowHandle to implement here or elsewhereCreates a window that implements a specified window procedure. ?
  //
  inherited;
end;

procedure TMyClipBoardListener.Loaded;
begin
  inherited;
  //
  if not(csDesigning in ComponentState) then
  begin
    FNextHWnd:= SetClipboardViewer(FInnerWindowHandle);
  end;
end;

procedure TMyClipBoardListener.WndProc(var Msg: TMessage);
begin
  with Msg do
  begin
    // Message to handle : WM_CHANGECBCHAIN and WM_DRAWCLIPBOARD
    // ... 
    else
      Result := DefWindowProc(FInnerWindowHandle, Msg, WParam, LParam); // <<< Is this the right way to do default handling properly?
  end;
end;

My question:

How can I get for my custom component an inner window implementing the embedded window procedure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱*していゐ 2025-01-02 09:41:46

AllocateHwnd em> 单位(不是表格)。

FInnerWindowHandle := AllocateHwnd(WndProc);

完成后,调用 DeallocateHwnd

Call AllocateHwnd from the Classes unit (not Forms).

FInnerWindowHandle := AllocateHwnd(WndProc);

When you're finished, call DeallocateHwnd.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文