如何使表单或窗口控件正常重建? [英] How do I make form or windowed control RecreateWnd-aware properly?
问题描述
StdCtrls
for 因此,当我需要在创建之后注册我的HWND,并在销毁之前取消注册,我应该覆盖相应的方法对。
简单看看控件
和表单
给了我3对,所有这些都是虚拟的:
- CreateHandle / DestroyHandle
- CreateWindowHandle / DestroyWindowHandle
- CreateWnd / DestroyWnd
有更多的对吗?我应该覆盖哪一个表单?而对于一般窗口控件,哪一对?
解决方案覆盖 CreateWnd()
和 DestroyWnd()
在大多数情况下。覆盖 DestroyWnd()
执行窗口取消注册,如果 csRecreating
标志存在于$ code> ControlState
属性,并调用继承的 DestroyWnd()
(调用 DestroyWindowHandle() code>)来破坏HWND。覆盖 CreateWnd()
调用继承的 CreateWnd()
(调用 CreateWindowHandle() / code>)创建HWND,加载和丢弃临时依赖于窗口的数据(如果有的话已保存),然后执行窗口注册。
覆盖 CreateWindowHandle()
和 DestroyWindowHandle()
当您需要通过其他方式获取/释放HWND Win32 CreateWindow / Ex()
和 DestroyWindow()
调用。例如, TForm
覆盖这些以通过发送 WM_MDICREATE
和 WM_MDIDESTROY来创建/释放MDI子窗口
消息到其 ClientHandle
窗口。
我从未见过 CreateHandle()
和 DestroyHandle()
覆盖任何有用的东西。
有关详细信息,请参阅此讨论:
CreateWnd和CreateWindowHandle之间有什么区别?
As you know, window handles of windowed controls (this includes forms) are considered volatile. That is, setting some properties may cause control to destroy its window handle and then recreate (there is a bunch of examples of that technique, search StdCtrls
for RecreateWnd
).
So, when I need to register my HWND with OS after creation and unregister it before destruction I should override corresponding method pair. Brief look to Controls
and Forms
gave me 3 pairs, all of them virtual:
- CreateHandle/DestroyHandle
- CreateWindowHandle/DestroyWindowHandle
- CreateWnd/DestroyWnd
Are there any more pairs? Which pair should I override for a form? And Which pair for general windowed control?
解决方案 Override CreateWnd()
and DestroyWnd()
in most situations. Override DestroyWnd()
to do window unregistrations, temporarily save any window-dependent data if the csRecreating
flag is present in the ControlState
property, and call the inherited DestroyWnd()
(which calls DestroyWindowHandle()
) to destroy the HWND. Override CreateWnd()
to call the inherited CreateWnd()
(which calls CreateWindowHandle()
) to create the HWND, load and discard temporary window-dependent data if any was previously saved, and do window registrations.
Override CreateWindowHandle()
and DestroyWindowHandle()
when you need to obtain/free an HWND through other means than normal Win32 CreateWindow/Ex()
and DestroyWindow()
calls. For example, TForm
overrides these to create/free MDI child windows by sending WM_MDICREATE
and WM_MDIDESTROY
messages to its ClientHandle
window.
I have never seen CreateHandle()
and DestroyHandle()
overridden for anything useful.
See this discussion for more details:
What's the difference between CreateWnd and CreateWindowHandle?
这篇关于如何使表单或窗口控件正常重建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!