/*
when using CDHtmlDialog to navigate a page frequently
and changing content and refresh it will crash in
ieframe.dll or mshtml.dll.
To avoid crash check browser busy state
before navigating a file in CDHtmlDialog
*/
//sample code to navigating html file
void CMYDHtmlDialog::NavigateFile()
{
CString csFilePath;
csFilePath = "c:\\sample.html";
//wait for 1 second if not loaded or in busy state
if( FALSE == WaitTillLoaded (1000) )
return;
Navigate(csFilePath, NULL, NULL);
}
//sample code to wait till page lode in browser
BOOL CMYDHtmlDialog::WaitTillLoaded (int nTimeout)
{
READYSTATE result;
DWORD nFirstTick = GetTickCount ();
do
{
m_pBrowserApp->get_ReadyState (&result);
if (result != READYSTATE_COMPLETE)
Sleep (50);
if (nTimeout > 0)
{
if ((GetTickCount () - nFirstTick) > nTimeout)
break;
}
} while (result != READYSTATE_COMPLETE);
if (result == READYSTATE_COMPLETE)
return TRUE;
else
return FALSE;
}
No comments:
Post a Comment