What external events trigger TCustomForm.RecreateWnd?

风格不统一 提交于 2019-12-23 08:44:53

问题


A particular VCL application is crashing, rarely, and apparently spontaneously, and I strongly suspect it is because the main form's window handle is being recreated in response to some external trigger from the operating system.

I do know for certain that if the main form's window handle were to change then trouble would certainly follow (because background threads post messages to this handle).

But I would like to know how to reproduce this bug before I set about making code changes intended to fix it, if only so I can confirm that this is a plausible cause of the crashes, that the symptoms match those reported, and that the code changes do indeed fix it. (Also if there is no way the OS can trigger a call to TCustomForm.RecreateWnd I need to find some other explanation for the crashes. Yes, I could post CM_RECREATEWND to the main form but that just begs the question.)

(I am aware that the correct way to post messages from background threads to the VCL thread is to create a hidden message window purely for this purpose using AllocateHWnd - that is my proposed fix.)

I have seen a similar error with a descendent of TCustomListView where RecreateWnd was being triggered by changing the desktop style from Windows XP to Windows Classic. But I haven't been able yet to find such a method to trigger RecreateWnd on a TCustomForm. (I've spent a considerable amount of time reading through the VCL code and I must be missing something.)

Summary:

Under what stimuli from the operating system does the VCL end up calling RecreateWnd on a TCustomForm? (I'm especially interested in Windows 7 if that makes a difference.)

If there is such a stimulus from the OS, I can prove whether it causes the observed symptoms. If there definitively isn't then I can prove window recreation isn't the cause.


回答1:


Windows will destroy your form if it is owned or parented to another window that is being destroyed.

That will cause your form's handle to be destroyed.

But since your form is still around, Delphi will re-create the handle the next time.



来源:https://stackoverflow.com/questions/27400973/what-external-events-trigger-tcustomform-recreatewnd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!