Is there any other way to load MSHTML documents without using Application.ProcessMessages?

Is there any other way to load MSHTML documents without using Application.ProcessMessages?

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

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

      

I want not to process the entire message queue at boot time because I will be changing the application flow, in other words, some messages that need to be processed after the download is complete may be processed earlier, even before the download is finished.

Is there a special message code that the IHTMLDocument expects during the download process? Or is there another way to download?

+2


source to share


3 answers


The call to Application.ProcessMessages is most likely necessary for the MSHTML ActiveX control time to finish loading the document. It looks like this is using collaborative multitasking to simulate the loading of a document in the background - ActiveX messages send messages to process the next snippet or whatever.

Typically, this will not affect the flow of your application, because the doc loading will happen as part of your normal message loop. But since you want to load the doc synchronously (don't do anything until the document is fully loaded), you will be sensitive to how it does background loading via messages.

One solution: see if the requirement for synchronous document loading can be removed. Let the download happen when it does, but move the check for readState = complete into a timer, perhaps 1 second intervals. When the timer detects that the document download is complete, then release your actions in the food chain.



Another solution: show a modal dialog while waiting for the document to load. Doing so can disable the rest of your user interface so you don't run the risk of re-entering. Calling ProcessMessages means that the user can still interact with your window, click buttons, menus, etc. This usually leads to problems. Displaying a modal dialog (progress dialog?) Avoids re-enabling by disabling everything behind the modal dialog.

Third possibility: Replace Application.ProcessMessages with PeekMessage and logic to validate the message to decide whether to allow it to go through or return it to the message queue for later use. It's a little messy, but it can work in special cases.

I recommend approach # 2, modal dialog.

+6


source


The TEmbeddedWB component contains some helper functions, such as LoadFromFile and LoadFromStream, that will directly load a document into an MSHTML control. Move the complete logic to the onDocumentComplete event.



+3


source


There is a TEmbeddedWB.OnDocumentComplete event that fires when the document finishes loading. Is there any special reason why you don't want to use it?

+1


source







All Articles