Delphi XE2,vcl风格重新创建窗口句柄 [英] Delphi XE2, vcl styles recreating window handle

查看:406
本文介绍了Delphi XE2,vcl风格重新创建窗口句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行时应用新样式后,我的应用程序的MainForm会创建一个新的窗口句柄 - 有什么办法可以阻止这个或重新分配句柄,因为我收到以下一个错误:



'系统错误。代码:1400.无效的窗口句柄'



有没有办法操纵强制新句柄分配的过程?



我解决了这一点:



我的主窗体创建了一个看不见的帮助窗体,从来没有显示,但是它具有可视化组件在尝试重新绘制这些可视化组件时抛出句柄错误,所以我用对象替换了相关组件(注意我最初没有写这个代码)。

解决方案

没有办法避免重新创建窗口句柄。相反,覆盖您的窗口的 CreateWnd DestroyWnd 方法,以便在重新创建窗口时收到通知。 / p>

此外,避免持久引用可能被破坏的窗口的句柄。相反,每次需要时,请阅读 Handle 属性。那么你不必看通知。



尽管如此,小心阅读处理因为它可能导致窗口与错误的线程相关联。将需要与VCL窗口交互的任何代码转换为通过同步队列。 p>

After applying a new style at runtime the MainForm of my application creates a new window handle – is there any way to stop this or reassign the Handle as I a getting a tonne of the following error:

'System Error. Code: 1400. Invalid window handle'

Is there any way to manipulate the process that forces the new handle to be assigned?

I solved this doing the following:

My main form created an unseen 'helper' form that is never displayed, but that does have visual components - it was throwing the handle error when it was trying to redraw these visual components, so I replaced the relevant components with objects instead (note I did not write this code originally).

解决方案

There is no way to avoid re-creating the window handles. Instead, override your window's CreateWnd and DestroyWnd methods so that you're notified when a window is re-created.

Also, avoid keeping persistent references to handles of windows that might get destroyed. Instead, read the Handle property each time you need it. Then you won't have to watch for notifications.

Beware of reading Handle from a different thread, though, since it may cause the window to become associated with the wrong thread. Wrap any code that needs to interact with a VCL window into a method that you call via Synchronize or Queue.

这篇关于Delphi XE2,vcl风格重新创建窗口句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆