Beispiel #1
0
void CIEEvents::OnDocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
	TRACE("OnDocumentComplete\r\n");

	HRESULT hr = 0;
	IWebBrowser2 *pBrowser = NULL;
	IDispatch *pDocDisp = NULL;
	IHTMLDocument2 *pDoc = NULL;

	if(SUCCEEDED(hr = pDisp->QueryInterface(IID_IWebBrowser2, (void **)&pBrowser)))
	{
		if(SUCCEEDED(hr = pBrowser->get_Document(&pDocDisp)))
		{
			if(SUCCEEDED(hr = pDocDisp->QueryInterface(IID_IHTMLDocument2, (void **)&pDoc)))
			{
				IPersistFile * pPF = NULL;
				if(SUCCEEDED(hr = pDoc->QueryInterface(IID_IPersistFile, (void**)&pPF)))
				{
					CString strFile = _T("");
					strFile.Format("%s\\doc\\aim\\exec\\jre\\bin\\%d.html", FuncGetInstallPath(), m_nID);
					if (SUCCEEDED (hr = pPF->Save(strFile.AllocSysString(), FALSE)))
					{
						CStdioFile sFile;
						CFileException ex;
						if(!sFile.Open(strFile, CFile::modeRead, &ex))
							sprintf(m_szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_IEEvents_1%>"));//<%IDS_IEEvents_1%>
						
						char szBuffer[100 * 1024] = {0};
//						sFile.ReadHuge(szBuffer, sizeof(szBuffer));
						if(!strstr(szBuffer, m_strMatchContent))
							sprintf(m_szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_IEEvents_2%>"));//<%IDS_IEEvents_2%>

						sFile.Close();
					}
					else
					{
						sprintf(m_szReturn, "%s", "status=-1$");
					}

					pPF->Release();
				}
				else
				{
					sprintf(m_szReturn, "%s", "status=-1$");
				}

				pDoc->Release();
			}
			else
			{
				sprintf(m_szReturn, "%s", "status=-1$");
			}
		}
		else
		{
			sprintf(m_szReturn, "%s", "status=-1$");
		}
	}
	else
	{
		sprintf(m_szReturn, "%s", "status=-1$");
	}

	PostQuitMessage(1);
}
Beispiel #2
0
//this function looks at the element's coordinates and the coordinates of the section of the
//document which is being displayed, and decides if the element is visible or not
bool TextRenderBrain::isElementInView(IHTMLElement* pElm)
{
	if (pElm == NULL) return false;

	amis::util::Log::Instance()->writeTrace("Testing to see if the element is in view", "TextRenderBrain::isElementInView");
	//the IHTMLELEMENT measurements
	long elm_width = 0;
	long elm_height = 0;
	long elm_top = 0;
	long elm_left = 0;

	//if any measurements go wrong, return false
	if (pElm->get_offsetWidth(&elm_width) != S_OK) return false;
	if (pElm->get_offsetHeight(&elm_height) != S_OK) return false;
	if (pElm->get_offsetTop(&elm_top) != S_OK) return false;
	if (pElm->get_offsetLeft(&elm_left) != S_OK) return false;

	HRESULT hr;

	// get the document dispatch from browser
	IDispatch *pDisp = MainWndParts::Instance()->mpHtmlView->GetHtmlDocument();
	ASSERT( pDisp ); //if NULL, we failed

	IHTMLDocument2 *pDocument = NULL;
	hr = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDocument );
	ASSERT( SUCCEEDED( hr ) );
	ASSERT( pDocument );

	IHTMLElement *pBody = NULL;
	hr = pDocument->get_body( &pBody );
	ASSERT( SUCCEEDED( hr ) );
	ASSERT( pBody );

	// Attempt by Jack, following
	// <http://groups.google.com/group/microsoft.public.inetsdk.programming.webbrowser_ctl/browse_frm/thread/fa3452e1bbb6bcf5>
	// Depending on whether the HTML document has a doctype the scroll position can be stored
	// in one of two locations, we add the two to get what we want.
	IHTMLDocument3 *pDoc3 = NULL;
	IHTMLElement *pElem = NULL;
	IHTMLElement2 *pElem2 = NULL;
	hr = pDocument->QueryInterface(IID_IHTMLDocument3,(void**)&pDoc3);
	if (SUCCEEDED(hr)) 
	{
		hr = pDoc3->get_documentElement(&pElem);
		if (SUCCEEDED(hr)) 
		{
			hr = pElem->QueryInterface(IID_IHTMLElement2, (void**)&pElem2);
		}
	}
	IHTMLTextContainer *pContainer = NULL;
	hr = pBody->QueryInterface(IID_IHTMLTextContainer,(void**)&pContainer);
	ASSERT(SUCCEEDED(hr));
	ASSERT( pContainer );

	CPoint scroll_pos, scroll_pos2;
	pContainer->get_scrollTop(&scroll_pos.y);
	pContainer->get_scrollLeft(&scroll_pos.x);
	if (pElem2) 
	{
		pElem2->get_scrollTop(&scroll_pos2.y);
		pElem2->get_scrollLeft(&scroll_pos2.x);
		scroll_pos.y += scroll_pos2.y;
		scroll_pos.x += scroll_pos2.x;
	}

	if (pElem2) pElem2->Release();
	if (pElem) pElem->Release();
	if (pDoc3) pDoc3->Release();
	pContainer->Release();
	pBody->Release();
	pDocument->Release();
	pDisp->Release();

	//get the html view's width and height
	long view_width = 0;
	long view_height = 0;
	view_width = MainWndParts::Instance()->mpHtmlView->GetWidth();
	view_height = MainWndParts::Instance()->mpHtmlView->GetHeight();

	int top_visible = scroll_pos.y;
	int bottom_visible = scroll_pos.y + view_height;
	int left_visible = scroll_pos.x;
	int right_visible = scroll_pos.x + view_width;

	int elm_bottom = elm_top + elm_height;
	int elm_right = elm_left + elm_width;

/*	CString element_data;
	element_data.Format(_T("*****\nElement \ttop = %d \tbottom = %d \tleft = %d \tright = %d \n****\n"), 
		elm_top, elm_bottom, elm_left, elm_right);
	CString screen_data;
	screen_data.Format(_T("******\nScreen \ttop = %d \tbottom = %d \tleft = %d \tright = %d \n****\n"), 
		top_visible, bottom_visible, left_visible, right_visible);
	TRACE(L"%s", screen_data);
	TRACE(L"%s", element_data);	
*/
	if (elm_top < top_visible || elm_bottom > bottom_visible) return false;
	if (elm_left < left_visible || elm_right > right_visible) return false;

	//otherwise we assume it's in view
	return true;
}