我应该如何为非可视 VCL 组件提供内部私有非可视窗口(句柄)?
这是一个后续问题。
我之前的问题:
我的问题:
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:
- How to paste a custom format clipboard data into a TMemo?
- Joining the Clipboard Chain Best practices?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从类
AllocateHwnd
em> 单位(不是表格)。完成后,调用
DeallocateHwnd
。Call
AllocateHwnd
from the Classes unit (not Forms).When you're finished, call
DeallocateHwnd
.