gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 15:18:36 24 4
gpt4 key购买 nike

这是一个后续问题。

我之前的问题:

我的问题:

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 .

关于delphi - 我应该如何为非可视 VCL 组件提供内部私有(private)非可 window 口(句柄)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8823878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com