簡體   English   中英

我應該如何提供一個非可視VCL組件的內部私有非可視窗口(句柄)?

[英]How should I provide an inner private non visual window (handle) a non visual VCL component?

這是一個后續問題。

我之前的問題:

我的問題:

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;

我的問題:

如何讓我的自定義組件實現嵌入式窗口過程的內部窗口?

單元(而不是表單 )調用AllocateHwnd

FInnerWindowHandle := AllocateHwnd(WndProc);

完成后,請致電DeallocateHwnd

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM