是否有另一种方法可以在不使用 Application.ProcessMessages 的情况下加载 MSHTML 文档?

发布于 2024-08-28 07:01:03 字数 344 浏览 9 评论 0原文

是否有另一种方法可以在不使用 Application.ProcessMessages 的情况下加载 MSHTML 文档?

要将文档加载到 IHTMLDocument 中,我需要这样做:

while Doc.readyState <> 'complete' do 
   Application.ProcessMessages;

我不想在加载期间处理所有消息队列,因为我会更改我的应用程序流程,换句话说,一些应该在加载后处理的消息完成可以更早处理,甚至在加载结束之前。

IHTMLDocument 期望在加载过程中提前提供特殊的消息代码?或者还有其他加载方式吗?

Is there another way to load MSHTML documents without use Application.ProcessMessages?

To load a document into a IHTMLDocument I need to do this:

while Doc.readyState <> 'complete' do 
   Application.ProcessMessages;

I want not to process all the message queue during the loading, because I would be changing my application flow, in other words, some messages that should be processed after the loading to be completed can be processed earlier, even before the loading end.

There is a special message code that the IHTMLDocument expect to advance in the loading process? Or there is another way to load?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人生戏 2024-09-04 07:01:03

对 Application.ProcessMessages 的调用很可能只是为了让 MSHTML activeX 控件有时间完成文档的加载。听起来他们在这里使用协作多任务处理来模拟在后台加载文档 - ActiveX 向自身发送消息以处理下一个块或其他内容。

通常,这不会影响您的应用程序的流程,因为文档加载将作为正常消息循环的一部分发生。但是,由于您希望同步加载文档(在文档完全加载之前不执行任何其他操作),因此您对它通过消息进行后台加载的方式很敏感。

一种解决方案:看看是否可以删除同步加载文档的要求。让负载在发生时发生,但将 readState = Complete 的检查移至计时器中,可能间隔 1 秒。当计时器发现文档加载完成时,然后启动下游食物链活动。

另一个解决方案:在等待文档加载时显示模式对话框。这样做的好处是禁用 UI 的其余部分,这样您就不会面临重入的风险。调用 ProcessMessages 意味着用户仍然可以与您的窗口交互,单击按钮、菜单等。通常这会导致问题。显示模式对话框(“进度对话框?”)可以通过禁用模式对话框后面的所有内容来避免重入。

第三种可能性:用 PeekMessage 替换 Application.ProcessMessages 并检查消息的逻辑以决定是否让它通过或将其放回消息队列以供稍后使用。这有点脏,但在非常特殊的情况下可能有效。

我推荐方法#2,即模式对话框。

The call to Application.ProcessMessages is most likely just needed to allow the MSHTML activeX control time to finish loading the document. It sounds like they're using cooperative multitasking here to simulate loading the doc in the background - the ActiveX posts messages to itself to process the next chunk or whatever.

Normally, this wouldn't affect your app's flow because the doc load would happen as part of your normal message loop. But because you're wanting to load the doc synchronously (not do anything else until the doc is fully loaded), you're sensitive to the way it's doing background loading via messages.

One solution: see if you can remove the requirement to load the doc synchronously. Let the load happen when it happens, but move the check for readState = complete into a timer, perhaps on a 1 second interval. When the timer discovers the doc load is complete, then fire off your downstream food chain activities.

Another solution: Display a modal dialog while waiting for the doc to load. This has the benefit of disabling the rest of your UI so you don't run the risk of reentrancy. Calling ProcessMessages means the user can still interact with your window, click on buttons, menus etc. Usually this will lead to problems. Displaying a modal dialog ("progress dialog?") avoids reentrancy by disabling everything behind the modal dialog.

Third possibility: Replace Application.ProcessMessages with PeekMessage and logic to examine the message to decide whether to let it go through or put it back on the message queue for later. This is a bit dirty but might work in very special cases.

I recommend approach #2, the modal dialog.

梅倚清风 2024-09-04 07:01:03

组件 TEmbeddedWB 包含一些辅助函数,例如 LoadFromFile 和 LoadFromStream,它们会将文档加载到 MSHTML 中直接控制。将完整的逻辑移至 onDocumentComplete 事件中。

The component TEmbeddedWB contains some helper functions such as LoadFromFile and LoadFromStream which will load the document into the MSHTML control directly. Move your complete logic into the onDocumentComplete event.

潦草背影 2024-09-04 07:01:03

有一个 TEmbeddedWB.OnDocumentComplete 事件,在文档完成加载时触发。您不想使用它有什么特殊原因吗?

There is a TEmbeddedWB.OnDocumentComplete event, fired when a document completes loading. Is there any special reason why you don't want to use that?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文