Пример #1
1
void IEView::scrollToBottom() {
    /*
    	IHTMLDocument2 *document = getDocument();
    	if (document != NULL) {
    		wchar_t *p = NULL;
    		if (SUCCEEDED(document->get_readyState(&p))) {
    		    int licznik = 0;
        		do {
              		if (FAILED(document->get_readyState(&p))) {
              		    break;
                    }
                    licznik++;
                    if (licznik == 1) break;
                    Sleep(10);
        		} while (!wcscmp(p, L"loading"));
    		}
    		IHTMLWindow2* pWindow = NULL;
    		if (SUCCEEDED(document->get_parentWindow( &pWindow )) && pWindow != NULL) {
    			pWindow->scrollBy( 0, 0x01FFFFFF );
    		}
    		document->Release();
    	}*/

    IHTMLDocument2 *document = getDocument();
    if (document != NULL) {
        IHTMLElementCollection *collection;
        IHTMLElement *element;
        IDispatch *dispatch;
        if (SUCCEEDED(document->get_all(&collection)) && (collection != NULL)) {
            long len;
            if (SUCCEEDED(collection->get_length(&len))) {
                VARIANT	variant;
                variant.vt = VT_I4;
                variant.lVal = len-1;
                if (SUCCEEDED(collection->item(variant, variant, &dispatch)) && (dispatch != NULL)) {
                    if (SUCCEEDED(dispatch->QueryInterface(IID_IHTMLElement,(void**)&element)) && (element != NULL)) {
                        variant.vt = VT_BOOL;
                        variant.boolVal = VARIANT_FALSE;
                        if (SUCCEEDED(element->scrollIntoView(variant))) {
                        }
                        element->Release();
                    }
                    dispatch->Release();
                }
            }
            collection->Release();
        }
        IHTMLWindow2* pWindow = NULL;
        if (SUCCEEDED(document->get_parentWindow( &pWindow )) && (pWindow != NULL)) {
            pWindow->scrollBy( -0x01FFFFFF, 0x01FFFFFF );
            pWindow->Release();
        }
        document->Release();
    }
}
Пример #2
0
bool IEView::mouseClick(POINT pt) {
	bool result = false;
	if (GetFocus() != hwnd) {
		getFocus = true;
	}
	IHTMLDocument2 *document = getDocument();
	if (document != NULL) {
		IHTMLElement *element;
		if (SUCCEEDED(document->elementFromPoint( pt.x, pt.y, &element ))&& element!=NULL) {
//		IHTMLAnchorElement * pAnchor;
//			if (SUCCEEDED(element->QueryInterface(IID_IHTMLAnchorElement, (void**)&pAnchor)) && (pAnchor!=NULL)) {
//				element->click();
//				result = true;
//				pAnchor->Release();
//			}
			BSTR url = getHrefFromAnchor(element);
			if (url != NULL) {
				if ((GetKeyState(VK_SHIFT) & 0x8000) && !(GetKeyState(VK_CONTROL) & 0x8000)
				&& !(GetKeyState(VK_MENU) & 0x8000)) {
					SendMessage(GetParent(hwnd), WM_COMMAND, IDCANCEL, 0);
				}
				CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW|OUF_TCHAR, (LPARAM) url);
				mir_free(url);
				result = true;
			}
			element->Release();
		}
		document->Release();
	}
	return result;
}
Пример #3
0
//-------------------------------------------------------------------------------
// Name: HrGetBody
// Desc: Получит тело Dockumeta если он создан ...
//-------------------------------------------------------------------------------
HRESULT COfsDhtmlEditCtrl::HrGetBody(IHTMLBodyElement** ppBody)
{
	HRESULT hr = E_FAIL;
	IHTMLDocument2* pDoc = NULL;

	*ppBody = NULL;

	if (SUCCEEDED(HrGetDoc(&pDoc)))
	{
		IHTMLElement* pElement = NULL;

		hr = pDoc->get_body(&pElement);

		if (SUCCEEDED(hr))
		{
			IHTMLBodyElement* pBody = NULL;
			hr = pElement->QueryInterface(IID_IHTMLBodyElement, (void **) &pBody);

			if (SUCCEEDED(hr))
			{
				*ppBody = pBody;

				// don't release body - we are returning it
			}
			
			pElement->Release();
		}

		pDoc->Release();
	}

	return hr;
}
Пример #4
0
/**
 * Returns the destination url (href) of the given anchor element (or parent anchor element)
 **/
BSTR IEView::getHrefFromAnchor(IHTMLElement *element) {
    if (element != NULL) {
    	IHTMLAnchorElement * pAnchor;
        if (SUCCEEDED(element->QueryInterface(IID_IHTMLAnchorElement, (void**)&pAnchor)) && (pAnchor!=NULL)) {
			VARIANT	variant;
            BSTR url;
            if (SUCCEEDED(element->getAttribute(L"href", 2, &variant) && variant.vt == VT_BSTR)) {
				url = Utils::dupString(variant.bstrVal);
				SysFreeString(variant.bstrVal);
			}
            //pAnchor->get_href( &url );
//            if (url!=NULL) {
  //          	url2 = Utils::dupString(url);
  //          	SysFreeString(url);
    //        	url = url2;
      //     	}
            pAnchor->Release();
            return url;
        } else {
            IHTMLElement * parent;
            if (SUCCEEDED(element->get_parentElement(&parent)) && (parent!=NULL)) {
            	BSTR url = getHrefFromAnchor(parent);
            	parent->Release();
            	return url;
           	}
        }
    }
    return NULL;
}
Пример #5
0
bool IEView::mouseClick(POINT pt) {
    bool result = false;
    if (GetFocus() != hwnd) {
		getFocus = true;
	}
	IHTMLDocument2 *document = getDocument();
	if (document != NULL) {
        IHTMLElement *element;
  		if (SUCCEEDED(document->elementFromPoint( pt.x, pt.y, &element ))&& element!=NULL) {
//		IHTMLAnchorElement * pAnchor;
//			if (SUCCEEDED(element->QueryInterface(IID_IHTMLAnchorElement, (void**)&pAnchor)) && (pAnchor!=NULL)) {
//				element->click();
//				result = true;
//				pAnchor->Release();
//			}
  			BSTR url = getHrefFromAnchor(element);
  			if (url != NULL) {
				if ((GetKeyState(VK_SHIFT) & 0x8000) && !(GetKeyState(VK_CONTROL) & 0x8000)
				&& !(GetKeyState(VK_MENU) & 0x8000)) {
					SendMessage(GetParent(hwnd), WM_COMMAND, IDCANCEL, 0);
				}
  			    int i = wcslen(url);
  			    char *tTemp = new char[i+1];
  			    WideCharToMultiByte(CP_ACP, 0, url, -1, tTemp, i+1, NULL, NULL);
		    	CallService(MS_UTILS_OPENURL, (WPARAM) 1, (LPARAM) tTemp);
                delete tTemp;
                delete url;
                result = true;
  			}
  			element->Release();
  		}
	    document->Release();
	}
	return result;
}
Пример #6
0
BSTR IEView::getHrefFromAnchor(IHTMLElement *element) {
    if (element != NULL) {
    	IHTMLAnchorElement * pAnchor;
        if (SUCCEEDED(element->QueryInterface(IID_IHTMLAnchorElement, (void**)&pAnchor)) && (pAnchor!=NULL)) {
            BSTR url;
            BSTR url2;
            pAnchor->get_href( &url );
            if (url!=NULL) {
            	url2 = wcsdup(url);
            	SysFreeString(url);
            	url = url2;
           	}
            pAnchor->Release();
            return url;
        } else {
            IHTMLElement * parent;
            if (SUCCEEDED(element->get_parentElement(&parent)) && (parent!=NULL)) {
            	BSTR url = getHrefFromAnchor(parent);
            	parent->Release();
            	return url;
           	}
        }
    }
    return NULL;
}
Пример #7
0
BOOL SimpleBrowser::GetElementText(LPCTSTR elementName, LPTSTR bf, UINT bfLen)
{
	IHTMLDocument3* pDocument = GetDocument3();
	if (pDocument == NULL)
		return FALSE;
	BOOL bRet = FALSE;
	IHTMLElement* pElement = NULL;
	CComBSTR elemName = elementName;
	if (pDocument->getElementById(elemName, &pElement) == S_OK && pElement != NULL)
	{
		CComBSTR innerText;
		if (pElement->get_innerText(&innerText) == S_OK)
		{
			if (innerText.Length() > 0)
			{
				_tcsncpy(bf, innerText, bfLen);
				bf[bfLen - 1] = 0;
			}
			else
				bf[0] = 0;
			bRet = TRUE;
		}
		pElement->Release();
	}
	pDocument->Release();
	return bRet;

}
void CIncrementSystemBFDlg::ProcessElementCollection(IHTMLElementCollection* pElemColl, CString id)
{	
	IDispatch* pElemDisp = NULL;
	IHTMLElement* pElem = NULL;
	VARIANT vID;
	VARIANT vIdx;

	VariantInit(&vID);
	vID.vt=VT_BSTR;
	vID.bstrVal=_bstr_t(id);

	VariantInit(&vIdx);
			  
	vIdx.vt=VT_I4;
	vIdx.lVal=0;

	HRESULT hr = pElemColl->item( vID, vIdx, &pElemDisp );
	if ( SUCCEEDED(hr) && pElemDisp != 0x0)
	{
		hr = pElemDisp->QueryInterface( IID_IHTMLElement, (void**)&pElem );
		if ( SUCCEEDED(hr) )
		{
			// Obtained element with ID of "myID".
			BSTR bsHtml;
			pElem->get_outerHTML(&bsHtml);
			CLogFile::WriteLog(bsHtml);

			ConnectButton1( pElem );
			pElem->Release();	
		}
		pElemDisp->Release();
	}
	pElemColl->Release();
}
Пример #9
0
bool IEView::mouseClick(POINT pt) {
    bool result = false;
    if (GetFocus() != hwnd) {
		getFocus = true;
	}
	IHTMLDocument2 *document = getDocument();
	if (document != NULL) {
        IHTMLElement *element;
  		if (SUCCEEDED(document->elementFromPoint( pt.x, pt.y, &element ))&& element!=NULL) {
  			BSTR url = getHrefFromAnchor(element);
  			if (url != NULL) {
  			    int i = wcslen(url);
  			    char *tTemp = new char[i+1];
  			    WideCharToMultiByte(CP_ACP, 0, url, -1, tTemp, i+1, NULL, NULL);
		    	CallService(MS_UTILS_OPENURL, (WPARAM) 1, (LPARAM) tTemp);
                delete tTemp;
                free (url);
                result = true;
  			}
  			element->Release();
  		}
	    document->Release();
	}
	return result;
}
Пример #10
0
AbstractWebElement *ExplorerElement::getOffsetParent()
{
	IHTMLElement *e;
	HRESULT hr = m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&e));
	ExplorerElement *parent = NULL;
	if (!FAILED(hr)  && e != NULL)
	{
		IHTMLElement *nativeParent;
		hr = e->get_offsetParent(&nativeParent);
		if (nativeParent != NULL) {
			parent = new ExplorerElement(nativeParent, m_pApp);
			nativeParent->Release();
		}
		e->Release();
	}
	return parent;
}
Пример #11
0
//-----------------------------------------------------------------------------
// Name: AddHtmlContentToElement
// Object: 
// Parameters :
//     in  : 
//     out : 
//     return : 
//-----------------------------------------------------------------------------
BOOL CHtmlViewer::AddHtmlContentToElement(TCHAR* Id,TCHAR* Content)
{
    if (this->pIWebBrowser==NULL)
        return FALSE;

    if (!this->IsPageCompleted())
        return FALSE;

    HRESULT hr;
    BOOL bRet;
    IDispatch* pHtmlDocDispatch = NULL;
    IHTMLDocument3* pHtmlDoc = NULL;
    IHTMLElement* pElem = NULL;
    BSTR bstrElementId;

#if ((!defined(UNICODE))&& (!defined(_UNICODE)))
    WCHAR* psz;
#endif

    // get IDispatch document interface
    hr = pIWebBrowser->get_Document(&pHtmlDocDispatch);
    if (FAILED (hr) || (pHtmlDocDispatch == NULL))
        return FALSE;

    // get IHTMLDocument3 document interface
    hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument3,(void**)&pHtmlDoc);
    if (FAILED (hr) || (pHtmlDoc == NULL))
    {
        pHtmlDocDispatch->Release();
        return FALSE;
    }

    // get pointer to element from it's Id
#if (defined(UNICODE)||defined(_UNICODE))
    bstrElementId=SysAllocString(Id);
#else
    CAnsiUnicodeConvert::AnsiToUnicode(Id,&psz);
    bstrElementId=SysAllocString(psz);
    free(psz);    
#endif

    hr = pHtmlDoc->getElementById(bstrElementId,&pElem);
    SysFreeString(bstrElementId);
    if (FAILED (hr) || (pElem == NULL))
    {
        pHtmlDoc->Release();
        pHtmlDocDispatch->Release();
        return FALSE;
    }

    bRet=this->AddHtmlContentToElement(pElem,Content);

    pElem->Release();
    pHtmlDoc->Release();
    pHtmlDocDispatch->Release();

    return bRet;
}
Пример #12
0
void ExplorerElement::click()
{
	IHTMLElement *e;
	HRESULT hr = m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&e));
	if (!FAILED(hr) && e != NULL)
	{
		hr = e->click();
		e->Release();
	}
}
Пример #13
0
void ExplorerElement::setTextContent(const char* text) {
	IHTMLElement *e;
	HRESULT hr = m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&e));
	if (!FAILED(hr) && e != NULL)
	{
		BSTR bstrValue = Utils::str2bstr(text);
		hr = e->put_innerText(bstrValue);
		SysFreeString(bstrValue);
		e->Release();
	}
}
Пример #14
0
void ExplorerElement::removeAttribute(const char* attribute) {
	IHTMLElement *e;
	HRESULT hr = m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&e));
	if (!FAILED(hr) && e != NULL)
	{
		BSTR bstrValue = Utils::str2bstr(attribute);
		VARIANT_BOOL v;
		hr = e->removeAttribute(bstrValue, 0, &v);
		SysFreeString(bstrValue);
		e->Release();
	}
}
Пример #15
0
void ExplorerElement::getTagName(std::string & value)
{
	IHTMLElement *e;
	value.clear ();
	HRESULT hr = m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&e));
	if (!FAILED(hr) && e != NULL)
	{
		BSTR bstrTag;
		hr = e->get_tagName(&bstrTag);
		if (!FAILED(hr) && bstrTag != NULL) {
			Utils::bstr2str(value, bstrTag);
			SysFreeString(bstrTag);
		}
		e->Release();
	}
}
Пример #16
0
//-----------------------------------------------------------------------------
// Name: AddHtmlContentToBody
// Object: 
// Parameters :
//     in  : 
//     out : 
//     return : 
//-----------------------------------------------------------------------------
BOOL CHtmlViewer::AddHtmlContentToBody(TCHAR* Content)
{
    HRESULT hr;
    BOOL bRet;
    IDispatch* pHtmlDocDispatch = NULL;
    IHTMLDocument2* pHtmlDoc = NULL;
    IHTMLElement* pElem = NULL;

    if (this->pIWebBrowser==NULL)
        return FALSE;

    if (!this->IsPageCompleted())
        return FALSE;

    // get IDispatch document interface
    hr = pIWebBrowser->get_Document(&pHtmlDocDispatch);
    if (FAILED (hr) || (pHtmlDocDispatch == NULL))
        return FALSE;

    // get IHTMLDocument2 document interface
    hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&pHtmlDoc);
    if (FAILED (hr) || (pHtmlDoc == NULL))
    {
        pHtmlDocDispatch->Release();
        return FALSE;
    }

    // get body
    hr = pHtmlDoc->get_body(&pElem);
    if (FAILED (hr) || (pElem == NULL))
    {
        pHtmlDoc->Release();
        pHtmlDocDispatch->Release();
        return FALSE;
    }

    bRet=this->AddHtmlContentToElement(pElem,Content);

    pElem->Release();
    pHtmlDoc->Release();
    pHtmlDocDispatch->Release();

    return bRet;
}
Пример #17
0
void DoClick(LPCTSTR windowName, LPCTSTR elementId, LPCTSTR elementName)
{
	MessageBox(NULL, "Started", "Info", MB_OK);
	CoInitialize( NULL );
	
	IHTMLDocument2* pDoc2 = NULL;
	pDoc2 = GetDoc2(windowName);

	if(pDoc2 != NULL)
	{
		IHTMLElement* pElem = FindElement(pDoc2, elementId, elementName);
		if(pElem != NULL)
		{
			pElem->click();
			pElem->Release();
		}

		pDoc2->Release();
	}

	CoUninitialize();
}
Пример #18
0
void CHtmlViewer::OnDocumentCompleted()
{
    // disconnect / remove old documents events
    if (this->pDocumentElementEvents)
        delete this->pDocumentElementEvents;

    // attach new documents events
    HRESULT hr;
    IDispatch* pHtmlDocDispatch = NULL;
    IHTMLDocument3* pHtmlDoc = NULL;
    // Retrieve the document object.

    hr = pIWebBrowser->get_Document(&pHtmlDocDispatch);
    if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
    {
        hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument3,(void**)&pHtmlDoc);
        if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
        {

            IHTMLElement* pElem = NULL;
            pHtmlDoc->get_documentElement(&pElem);

            this->pDocumentElementEvents=new CElementEvents(pElem);
            this->pDocumentElementEvents->ConnectEvents();

            this->pDocumentElementEvents->SetElementEventsCallBack(this->ElementEventsCallBack,this->ElementEventsCallBackUserParam);
            this->pDocumentElementEvents->SetElementEventsCallBackEx(this->ElementEventsCallBackEx,this->ElementEventsCallBackExUserParam);

            this->pDocumentElementEvents->EnableSelection(this->bEnableSelection);
            this->pDocumentElementEvents->EnableContextMenu(this->bEnableContextMenu);

            pElem->Release();
            pHtmlDoc->Release();
        }

        pHtmlDocDispatch->Release();
    }
}
Пример #19
0
HRESULT TestDocumentText(IHTMLDocument3 *pHtmlDoc, BSTR &message)
{
	IHTMLDocument2 *pDoc = NULL;
	IHTMLElement *pElem = NULL;
	BSTR bstrId = SysAllocString(L"test");

	HRESULT hr = pHtmlDoc->QueryInterface(IID_PPV_ARGS(&pDoc));
	if (SUCCEEDED(hr) && pDoc) {
		hr = pDoc->get_body(&pElem);
		if (SUCCEEDED(hr) && pElem) {
			BSTR bstrText = NULL;
			pElem->get_innerText(&bstrText);
			message = SysAllocString(bstrText);
			SysFreeString(bstrText);
			pElem->Release();
		}

		pDoc->Release();
	}

	SysFreeString(bstrId);
	return hr;
}
Пример #20
0
void ExplorerElement::setAttribute(const char *attribute, const char*value)
{
	if (strcmp (attribute,"style") == 0)
		setStyleAttribute (m_pElement, value);
	else
	{
		if (strcmp (attribute, "class") == 0)
			attribute = "className";
		IHTMLElement *e;
		HRESULT hr = m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&e));
		if (!FAILED(hr) && e != NULL)
		{
			BSTR bstrAttribute = Utils::str2bstr(attribute);
			BSTR bstrValue = Utils::str2bstr(value);
			VARIANT v;
			v.vt = VT_BSTR;
			v.bstrVal = bstrValue;
			hr = e->setAttribute(bstrAttribute, v,  1 /* respecte case*/);
			SysFreeString(bstrValue);
			SysFreeString(bstrAttribute);
			e->Release();
		}
	}
}
Пример #21
0
void ExplorerElement::getAttribute(const char *attribute, std::string & value)
{
	if (strcmp (attribute,"style") == 0)
		getStyleAttribute (m_pElement, value);
	else
	{
		IHTMLElement *e;
		value.clear();
		HRESULT hr = m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&e));
		if (!FAILED(hr) && e != NULL)
		{
			BSTR bstr = Utils::str2bstr(attribute);
			VARIANT v;
			hr = e->getAttribute(bstr, 2 /* as bstr*/, &v);
			if (!FAILED(hr) && v.vt == VT_BSTR)
			{
				Utils::bstr2str(value, v.bstrVal);
				SysFreeString(v.bstrVal);
			}
			SysFreeString(bstr);
			e->Release();
		}
	}
}
Пример #22
0
HRESULT STDMETHODCALLTYPE CElementEvents::Invoke(DISPID dispidMember,
                                                REFIID riid,
                                                LCID lcid,
                                                WORD wFlags,
                                                DISPPARAMS* pdispparams,
                                                VARIANT* pvarResult,
                                                EXCEPINFO* pexcepinfo,
                                                UINT* puArgErr)
{
    UNREFERENCED_PARAMETER(puArgErr);
    UNREFERENCED_PARAMETER(pexcepinfo);
    UNREFERENCED_PARAMETER(pvarResult);
    UNREFERENCED_PARAMETER(riid);
    UNREFERENCED_PARAMETER(lcid);
    UNREFERENCED_PARAMETER(wFlags);
    // try to get IHTMLEventObj
    IDispatch* param1=NULL; 
    if (pdispparams->cArgs==1 && (pdispparams->rgvarg[0].vt==VT_DISPATCH))
        param1=pdispparams->rgvarg[0].pdispVal;

    IHTMLEventObj* pEvtObj=NULL;
    if (param1) 
        param1->QueryInterface(IID_IHTMLEventObj, (void**)&pEvtObj);


    // see HTMLElementEvents2 Dispinterface for available values (include mshtmdid.h)

    // disable context menu by default (but for INPUT)
    switch (dispidMember)
    {
    case DISPID_HTMLELEMENTEVENTS2_ONCONTEXTMENU:
        if (this->bEnableContextMenu)
            break;
        // else
        {
            IHTMLElement* pHTMLElement;
            BSTR String;
            // get element source of event
            HRESULT hr=pEvtObj->get_srcElement(&pHTMLElement);
            if (SUCCEEDED(hr) && pHTMLElement)
            {
                // get element name
                pHTMLElement->get_tagName(&String);
                if (String==NULL)
                    String=SysAllocString(L"");

                // apply for all but input
                if (wcsicmp(String,L"INPUT")!=0)
                {
                    VARIANT v;
                    v.vt=VT_BOOL;
                    v.boolVal=VARIANT_FALSE;
                    pEvtObj->put_returnValue(v);
                }

                // Free memory and release objects
                SysFreeString(String);
                pHTMLElement->Release();
            }
        }
        break;

    // disable selection but for input
    case DISPID_HTMLELEMENTEVENTS2_ONSELECTSTART:
        if (this->bEnableSelection)
            break;
        // else
        {
            IHTMLElement* pHTMLElement;
            BSTR String;
            // get element source of event
            HRESULT hr=pEvtObj->get_srcElement(&pHTMLElement);
            if (SUCCEEDED(hr) && pHTMLElement)
            {
                // get element name
                pHTMLElement->get_tagName(&String);
                if (String==NULL)
                    String=SysAllocString(L"");

                // apply for all but input
                if (wcsicmp(String,L"INPUT")!=0)
                {
                    VARIANT v;
                    v.vt=VT_BOOL;
                    v.boolVal=VARIANT_FALSE;
                    pEvtObj->put_returnValue(v);
                }

                // Free memory and release objects
                SysFreeString(String);
                pHTMLElement->Release();
            }
        }
        break;
    // disable selection but for input
    case DISPID_HTMLELEMENTEVENTS2_ONMOUSEOVER:
        if (this->bEnableSelection || (this->pCmdTarget==NULL))
            break;
        // else
        {
            VARIANT var;
            var.vt=VT_BOOL;
            IHTMLElement* pHTMLElement;
            BSTR String;

            // get element source of event
            HRESULT hr=pEvtObj->get_srcElement(&pHTMLElement);
            if (SUCCEEDED(hr) && pHTMLElement)
            {
                // get element name
                pHTMLElement->get_tagName(&String);
                if (String==NULL)
                    String=SysAllocString(L"");

                // apply for all but input, link and img
                if ( (wcsicmp(String,L"INPUT")!=0)
                    && (wcsicmp(String,L"A")!=0)
                    && (wcsicmp(String,L"IMG")!=0)
                    )
                {
                    // stop cursor automatic mode
                    var.boolVal = VARIANT_TRUE;
                    this->pCmdTarget->Exec(&CGID_MSHTML, 
                                            IDM_OVERRIDE_CURSOR,
                                            OLECMDEXECOPT_DODEFAULT,
                                            &var,
                                            NULL);
                    // Set cursor to arrow
                    this->hCursorOld=::SetCursor(this->hCursorArrow);
                }

                // Free memory and release objects
                SysFreeString(String);
                pHTMLElement->Release();
            }
        }
        break;
    case DISPID_HTMLELEMENTEVENTS2_ONMOUSEOUT:
        if (this->bEnableSelection || (this->pCmdTarget==NULL))
            break;
        // else
        {
            VARIANT var;
            var.vt=VT_BOOL;
            IHTMLElement* pHTMLElement;
            BSTR String;

            // get element source of event
            HRESULT hr=pEvtObj->get_srcElement(&pHTMLElement);
            if (SUCCEEDED(hr) && pHTMLElement)
            {
                // get element name
                pHTMLElement->get_tagName(&String);
                if (String==NULL)
                    String=SysAllocString(L"");

                // apply for all but input, link and img
                if ( (wcsicmp(String,L"INPUT")!=0)
                    && (wcsicmp(String,L"A")!=0)
                    && (wcsicmp(String,L"IMG")!=0)
                    )
                {
                    // restore cursor automatic mode
                    var.boolVal = VARIANT_FALSE;
                    ::SetCursor(this->hCursorOld);
                    this->pCmdTarget->Exec(&CGID_MSHTML, 
                                            IDM_OVERRIDE_CURSOR, 
                                            OLECMDEXECOPT_DODEFAULT, 
                                            &var, 
                                            NULL);
                }
                // Free memory and release objects
                SysFreeString(String);
                pHTMLElement->Release();
            }
        }
        break;
    case DISPID_HTMLELEMENTEVENTS2_ONDRAGSTART:
        if (this->bEnableSelection)
            break;
        {
            VARIANT v;
            v.vt=VT_BOOL;
            v.boolVal=VARIANT_FALSE;
            pEvtObj->put_returnValue(v);
        }
        break;
    }


    // call callback
    if (this->ElementEventsCallBack)
    {
        IHTMLElement* pHTMLElement;
        BSTR String;
        // get element source of event
        HRESULT hr=pEvtObj->get_srcElement(&pHTMLElement);
        if (SUCCEEDED(hr) && pHTMLElement)
        {
            // get element id
            pHTMLElement->get_id(&String);
            if (String==NULL)
                String=SysAllocString(L"");

            // call callback
            this->ElementEventsCallBack(dispidMember,String,this->ElementEventsCallBackUserParam);

            // Free memory and release objects
            SysFreeString(String);
            pHTMLElement->Release();
        }
    }

    if (this->ElementEventsCallBackEx)
    {
        this->ElementEventsCallBackEx(dispidMember,pEvtObj,this->ElementEventsCallBackExUserParam);
    }

    // release IHTMLEventObj
    if (pEvtObj)
        pEvtObj->Release();

    return S_OK;
}
Пример #23
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;
}
Пример #24
0
void CWebDlg::OnDocumentComplete(LPDISPATCH pDisp, VARIANT FAR* URL) 
{
	IHTMLDocument2*	pHTMLDocument2;
	LPDISPATCH		lpDispatch;
	lpDispatch =	m_explore.GetDocument();

    if (lpDispatch)
	{
		HRESULT hr;
		hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*) &pHTMLDocument2);
		lpDispatch->Release();

		if (FAILED(hr))
			return;

		if (pHTMLDocument2 == NULL)
			return;

		IHTMLElement* pBody;
		hr = pHTMLDocument2->get_body(&pBody);

		if (FAILED(hr))
			return;

		if (pBody == NULL)
			return;

		BSTR bstr;
		pBody->get_innerHTML(&bstr);
		
		CString csSourceCode(bstr);
		CString csAction;
		CString csComment;

		SysFreeString(bstr);
		pBody->Release();

		if(csSourceCode.Find("newlogin") != -1)
		{
			// Authentication not ok !
			APP.m_bAuthGame	= FALSE;
			APP.m_bAuthWeb	= FALSE;
			((CNel_launcherDlg*)AfxGetMainWnd())->m_wndTabs.DestroyWindow();
			DestroyWindow();
			((CNel_launcherDlg*)AfxGetMainWnd())->Login();
			return;
		}

// ACE: BADDDDDD!!!! the good web page can contains 404 in the cookie because the cookie contains any number we want
/*		else if(csSourceCode.Find("404") != -1)
		{
			// Authentication lost, try to redo the authentication
			CLoginDlg	dlg;

			dlg.AuthWeb();
			OpenUrl(m_csUrl);
			return;
		}
*/		int	iFindAction1	= csSourceCode.Find("<!--nel");
		int	iFindAction2;
		int	iFindComment1;
		int	iFindComment2;

		if(iFindAction1 != -1)
		{
			iFindAction1	= csSourceCode.Find('"', iFindAction1);
			if(iFindAction1 != -1)
			{
				iFindAction2	= csSourceCode.Find('"', iFindAction1+1);
				if(iFindAction2 != -1)
				{
					csAction	= csSourceCode.Mid(iFindAction1+1, iFindAction2 - iFindAction1-1);
					
					iFindComment1	= iFindAction2 + 2;
					if(iFindComment1 != -1)
					{
						iFindComment2	= csSourceCode.Find("-->", iFindAction1);
						if(iFindComment2 != -1)
						{
							csComment	= csSourceCode.Mid(iFindComment1, iFindComment2 - iFindComment1);
							csComment.TrimRight();
							csComment.TrimLeft();

							if(csAction == "launch")
								((CNel_launcherDlg*)GetParent())->launch(csComment);
							else if(csAction == "patch")
								((CNel_launcherDlg*)GetParent())->patch(csComment);
						}
					}
				}
			}
		}
	}
//	m_dlgLoading.ShowWindow(SW_HIDE);
}
Пример #25
0
BOOL CHtmlViewer::SaveAs(TCHAR* FileName)
{
    if (this->pIWebBrowser==NULL)
        return FALSE;

    BOOL bSuccess=FALSE;

    // this->pIWebBrowser->ExecWB(OLECMDID_SAVEAS,...) troubles : 
    // don't get updated content 
    // don't update res:// links)

    // this saving way troubles : don't save remote files only res and file protocols supported

    CHtmlViewerSave_FirstItem FirstItem;

    HRESULT hr;
    HANDLE hFile;
    IDispatch* pHtmlDocDispatch = NULL;
    IHTMLDocument3* pHtmlDoc = NULL;
    // Retrieve the document object.

    hr = pIWebBrowser->get_Document(&pHtmlDocDispatch);
    if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
    {
        hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument3,(void**)&pHtmlDoc);
        if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
        {

            IHTMLElement* pElem = NULL;

            hr = pHtmlDoc->get_documentElement(&pElem);
            if (SUCCEEDED (hr) && (pElem != NULL))
            {

                BSTR bstrDocContent;
                pElem->get_innerHTML(&bstrDocContent);
                TCHAR* pDocContent;
                TCHAR* pszCurrent;
                TCHAR* pszResProtocol;
                TCHAR* pszResProtocolEnd;
                TCHAR* pszFileProtocol;
                TCHAR* pszFileProtocolEnd;
                TCHAR* pszDontSaveBegin;
                TCHAR* pszDontSaveEnd;
                TCHAR* pszMin;
                TCHAR* psz;
                TCHAR Link[MAX_PATH];
                TCHAR ChangedLink[MAX_PATH];
    #if (defined(UNICODE)||defined(_UNICODE))
                pDocContent=bstrDocContent;
    #else
                CAnsiUnicodeConvert::UnicodeToAnsi(bstrDocContent,&pDocContent);
    #endif
                if (CTextFile::CreateTextFile(FileName,&hFile))
                {
                    CTextFile::WriteText(hFile,CHtmlViewer_DOCUMENT_HEADER);

                    pszCurrent=pDocContent;

                    for (;;)
                    {
                        // find next dont save begin
                        pszDontSaveBegin=_tcsstr(pszCurrent,CHtmlViewer_DONT_SAVE_BEGIN);

                        // find next file:// protocol
                        pszFileProtocol=_tcsstr(pszCurrent,CHtmlViewer_FILE_PROTOCOL);

                        // find next res:// protocol (like "res://foo.exe/jpg/105")
                        pszResProtocol=_tcsstr(pszCurrent,CHtmlViewer_RES_PROTOCOL);


                        // if no more res::// protocol, file:// protocol or <!--DONT_SAVE_BEGIN-->
                        if ((pszResProtocol==NULL)
                            && (pszFileProtocol==NULL)
                            && (pszDontSaveBegin==NULL)
                            ) 
                        {
                            CTextFile::WriteText(hFile,pszCurrent);
                            break;
                        }

                        // at least one item is not null
                        // get first not null item
                        if (pszDontSaveBegin)
                            pszMin=pszDontSaveBegin;
                        else
                            pszMin=(TCHAR*)-1;
                        FirstItem=CHtmlViewerSave_FirstItem_DontSave;

                        if ((pszFileProtocol<pszMin)
                            && (pszFileProtocol!=0)
                            )
                        {
                            FirstItem=CHtmlViewerSave_FirstItem_File;
                            pszMin=pszFileProtocol;
                        }

                        if ((pszResProtocol<pszMin)
                            && (pszResProtocol!=0)
                            )
                        {
                            FirstItem=CHtmlViewerSave_FirstItem_Res;
                            pszMin=pszResProtocol;
                        }

                        // do treatment for first found type
                        // (use if instead case to allow breaking for(;;). Else we need a goto)
                        if (FirstItem==CHtmlViewerSave_FirstItem_Res)
                        {
                            // write data before res:// protocol
                            CTextFile::WriteText(hFile,pszCurrent,pszResProtocol-pszCurrent+1);

                            // look for the end of res:// protocol
                            pszResProtocolEnd=_tcschr(pszResProtocol+_tcslen(CHtmlViewer_RES_PROTOCOL),'"');
                            if (!pszResProtocolEnd)
                            {
                                // bad html format, output raw content
                                SetFilePointer(hFile,0,0,FILE_BEGIN);
                                CTextFile::WriteText(hFile,CHtmlViewer_DOCUMENT_HEADER);
                                CTextFile::WriteText(hFile,pDocContent);
                                break;
                            }

                            _tcsncpy(Link,pszResProtocol,pszResProtocolEnd-pszResProtocol+1);
                            Link[pszResProtocolEnd-pszResProtocol+1]=0;

                            // change link from resource one to extracted resource one
                            this->ModifyLinkAndExtractResource(FileName,Link,ChangedLink);
                            // write modified link
                            CTextFile::WriteText(hFile,ChangedLink);
                            // end link by adding '"'
                            CTextFile::WriteText(hFile,_T("\""));

                            // pointer after res protocol
                            pszCurrent=pszResProtocolEnd+1;
                        }
                        else if (FirstItem==CHtmlViewerSave_FirstItem_File)
                        {
                            // write data before file:// protocol
                            CTextFile::WriteText(hFile,pszCurrent,pszFileProtocol-pszCurrent+1);

                            // look for the end of file:// protocol
                            pszFileProtocolEnd=_tcschr(pszFileProtocol+_tcslen(CHtmlViewer_FILE_PROTOCOL),'"');
                            if (!pszFileProtocolEnd)
                            {
                                // bad html format, output raw content
                                SetFilePointer(hFile,0,0,FILE_BEGIN);
                                CTextFile::WriteText(hFile,CHtmlViewer_DOCUMENT_HEADER);
                                CTextFile::WriteText(hFile,pDocContent);
                                break;
                            }
                            pszFileProtocol+=_tcslen(CHtmlViewer_FILE_PROTOCOL);
                            _tcsncpy(Link,pszFileProtocol,pszFileProtocolEnd-pszFileProtocol);
                            Link[pszFileProtocolEnd-pszFileProtocol]=0;
                            

                            // get saving filename
                            _tcscpy(ChangedLink,FileName);
                            // remove file extension of saving file name
                            CStdFileOperations::RemoveFileExt(ChangedLink);
                            // add "_files\" to saving file to create a directory like SavingFileName_files
                            _tcscat(ChangedLink,CHtmlViewer_FILES_DIR_EXT);
                            // add the name of file
                            _tcscat(ChangedLink,CStdFileOperations::GetFileName(Link));
                            // create directory if necessary
                            CStdFileOperations::CreateDirectoryForFile(ChangedLink);
                            // copy file to directory
                            CopyFile(Link,ChangedLink,FALSE);
                           
                            // now make a relative link to file
                            _tcscpy(Link,ChangedLink);
                            psz=_tcsrchr(Link,'\\');
                            if (psz)
                            {
                                *psz='/';
                                psz=_tcsrchr(Link,'\\');
                                if (psz)
                                {
                                    _tcscpy(ChangedLink,psz+1);
                                }
                            }

                            // write modified link
                            CTextFile::WriteText(hFile,ChangedLink);
                            // end link by adding '"'
                            CTextFile::WriteText(hFile,_T("\""));

                            // pointer after file protocol
                            pszCurrent=pszFileProtocolEnd+1;
                        }
                        else if (FirstItem==CHtmlViewerSave_FirstItem_DontSave)
                        {
                            // write data before <!--DONT_SAVE_BEGIN-->
                            CTextFile::WriteText(hFile,pszCurrent,pszDontSaveBegin-pszCurrent);

                            pszDontSaveEnd=_tcsstr(pszDontSaveBegin+_tcslen(CHtmlViewer_DONT_SAVE_BEGIN),CHtmlViewer_DONT_SAVE_END);
                            if (!pszDontSaveEnd)
                            {
                                // bad html format, output raw content
                                SetFilePointer(hFile,0,0,FILE_BEGIN);
                                CTextFile::WriteText(hFile,CHtmlViewer_DOCUMENT_HEADER);
                                CTextFile::WriteText(hFile,pDocContent);
                                break;
                            }
                            // point after <!--DONT_SAVE_END-->
                            pszCurrent=pszDontSaveEnd+_tcslen(CHtmlViewer_DONT_SAVE_END);
                        }
                    }
                    CTextFile::WriteText(hFile,CHtmlViewer_DOCUMENT_FOOTER);
                    CloseHandle(hFile);

                    bSuccess=TRUE;
                }
    #if ((!defined(UNICODE))&& (!defined(_UNICODE)))
                // free allocated string for ansi
                free(pDocContent);
    #endif

                SysFreeString(bstrDocContent);

                pElem->Release();
            }
            pHtmlDoc->Release();
        }
        
        pHtmlDocDispatch->Release();
    }
    return bSuccess;
}
Пример #26
0
bool CMyInternetExplorer::FindAnchor (bool bClick, bool bFocus,
									  bool bName, bool bOuterText, bool bTooltip, bool bURL,
									  LPCTSTR sName, LPCTSTR sOuterText, LPCTSTR sTooltip, LPCTSTR sURL)
{
	ASSERT (m_pWebBrowser != NULL);
	if (m_pWebBrowser == NULL)
		return false;
	
	HRESULT hr;
	IDispatch* pHtmlDocDispatch = NULL;
	IHTMLDocument2 * pHtmlDoc = NULL;
	bool bSearch = true;

	// Retrieve the document object.
	hr = m_pWebBrowser->get_Document (&pHtmlDocDispatch);
	if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
	{
		hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2,  (void**)&pHtmlDoc);
		if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
		{
			IHTMLElementCollection* pColl = NULL;
			hr = pHtmlDoc->get_all (&pColl);

			if (SUCCEEDED (hr) && (pColl != NULL))
			{
				// Obtained the Anchor Collection...
				long nLength = 0;
				pColl->get_length (&nLength);
				
				for (int i = 0; i < nLength && bSearch; i++)
				{
					COleVariant vIdx ((long)i, VT_I4);
					
					IDispatch* pElemDispatch = NULL;
					IHTMLElement * pElem = NULL;
					
					hr = pColl->item (vIdx, vIdx, &pElemDispatch);
					
					if (SUCCEEDED (hr) && (pElemDispatch != NULL))
					{
						hr = pElemDispatch->QueryInterface (IID_IHTMLElement, (void**)&pElem);
						
						if (SUCCEEDED (hr) && (pElem != NULL))
						{
							BSTR bstrTagName;
							CString sTempTagName;
							if (!FAILED (pElem->get_tagName (&bstrTagName)))
							{
								sTempTagName = bstrTagName;
								SysFreeString (bstrTagName);
							}
							
							if (sTempTagName == _T ("a") || sTempTagName == _T ("A"))
							{
								IHTMLAnchorElement * pAnchor = NULL;
								hr = pElemDispatch->QueryInterface(IID_IHTMLAnchorElement, (void**)&pAnchor);
								
								if (SUCCEEDED (hr) && (pAnchor != NULL))
								{
									BSTR bstrName, bstrOuterText, bstrURL, bstrTooltip;
									CString sTempName, sTempOuter, sTempURL, sTempTooltip;
									
									if (!FAILED (pElem->get_outerText (&bstrOuterText)))
									{
										sTempOuter = bstrOuterText;
										SysFreeString (bstrOuterText);
									}
									if (!FAILED (pElem->get_title (&bstrTooltip)))
									{
										sTempTooltip = bstrTooltip;
										SysFreeString (bstrTooltip);
									}
									if (!FAILED (pAnchor->get_name (&bstrName)))
									{
										sTempName = bstrName;
										SysFreeString (bstrName);
									}
									if (!FAILED (pAnchor->get_href (&bstrURL)))
									{
										sTempURL = bstrURL;
										SysFreeString (bstrURL);
									}

									// Do the comparison here!
									bool bMatches = true;
									if (bMatches && bName)
									{
										if (!StringHelper::WildcardCompareNoCase (sName, sTempName))
											bMatches = false;
									}
									if (bMatches && bOuterText)
									{
										if (!StringHelper::WildcardCompareNoCase (sOuterText, sTempOuter))
											bMatches = false;
									}
									if (bMatches && bURL)
									{
										if (!StringHelper::WildcardCompareNoCase (sURL, sTempURL))
											bMatches = false;
									}
									if (bMatches && bTooltip)
									{
										if (!StringHelper::WildcardCompareNoCase (sTooltip, sTempTooltip))
											bMatches = false;
									}
									
									if (bMatches)
									{
										// No need to search more!
										bSearch = false;
										
										if (bFocus)
											pAnchor->focus ();
										if (bClick)
											pElem->click ();
									}
									pAnchor->Release ();
								}
							}
							pElem->Release ();
						}
						pElemDispatch->Release ();
					}		
				}
				pColl->Release ();
			}
			pHtmlDoc->Release();
		}
		pHtmlDocDispatch->Release ();
	}
	
	if (bSearch == false)
		return true;

	return false;
}
Пример #27
0
bool CMyInternetExplorer::GetInput  (IDispatch* pHtmlDocDispatch,bool bClick, bool bSelect, bool bChangeValue, bool bSetCheck,
									  bool bType, bool bName, bool bValue, 
									  LPCTSTR sTypeToLook, LPCTSTR sNameToLook, LPCTSTR sValueToLook,
									  bool bNewCheckValue, LPCTSTR sNewValue,LPTSTR szValue)
{
//	ASSERT (m_pWebBrowser != NULL);
//	if (m_pWebBrowser == NULL)
//		return false;
	
	HRESULT hr;
//	IDispatch* pHtmlDocDispatch = NULL;
	IHTMLDocument2 * pHtmlDoc = NULL;
	bool bSearch = true;

	// Retrieve the document object.
//	hr = m_pWebBrowser->get_Document (&pHtmlDocDispatch);
	if (true && (pHtmlDocDispatch != NULL))
	{
		hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2,  (void**)&pHtmlDoc);
		if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
		{
			IHTMLElementCollection* pColl = NULL;
			hr = pHtmlDoc->get_all (&pColl);

			if (SUCCEEDED (hr) && (pColl != NULL))
			{
				// Obtained the Anchor Collection...
				long nLength = 0;
				pColl->get_length (&nLength);
				
				for (int i = 0; i < nLength && bSearch; i++)
				{
					COleVariant vIdx ((long)i, VT_I4);
					
					IDispatch* pElemDispatch = NULL;
					IHTMLElement * pElem = NULL;
					
					hr = pColl->item (vIdx, vIdx, &pElemDispatch);
					
					if (SUCCEEDED (hr) && (pElemDispatch != NULL))
					{
						hr = pElemDispatch->QueryInterface (IID_IHTMLElement, (void**)&pElem);
						
						if (SUCCEEDED (hr) && (pElem != NULL))
						{
							BSTR bstrTagName;
							CString sTempTagName;
							if (!FAILED (pElem->get_tagName (&bstrTagName)))
							{
								sTempTagName = bstrTagName;
								sTempTagName.MakeLower ();
								//AfxMessageBox (sTempTagName);
								SysFreeString (bstrTagName);
							}
							if (sTempTagName == _T ("input"))
							{
								IHTMLInputElement * pInputElem = NULL;
								hr = pElemDispatch->QueryInterface (IID_IHTMLInputElement, (void**)&pInputElem);
								
								if (SUCCEEDED (hr) && (pInputElem != NULL))
								{
									BSTR bstrType, bstrName, bstrValue;
									CString sTempType, sTempName, sTempValue;
									
									if (!FAILED (pInputElem->get_type (&bstrType)))
									{
										sTempType = bstrType;
										SysFreeString (bstrType);
									}
									if (!FAILED (pInputElem->get_name (&bstrName)))
									{
										sTempName = bstrName;
										SysFreeString (bstrName);
									}
									if (!FAILED (pInputElem->get_value (&bstrValue)))
									{
										sTempValue = bstrValue;
										SysFreeString (bstrValue);
									}
									//AfxMessageBox (_T ("Name: ") + sTempName + _T ("\r\nType: ") + sTempType + _T ("\r\nValue: ") + sTempValue);
									// Do the comparison here!
									lstrcpy(szValue,sTempValue);
									bool bMatches = true;
									if (bMatches && bType)
									{
										if (!StringHelper::WildcardCompareNoCase (sTypeToLook, sTempType))
											bMatches = false;
									}
									if (bMatches && bName)
									{
										if (!StringHelper::WildcardCompareNoCase (sNameToLook, sTempName))
											bMatches = false;
									}
									if (bMatches && bValue)
									{
										if (!StringHelper::WildcardCompareNoCase (sValueToLook, sTempValue))
											bMatches = false;
									}
									
									if (bMatches)
									{
										// No need to search more!
										bSearch = false;

										if (bSetCheck)
										{
											if (bNewCheckValue)
												pInputElem->put_checked (VARIANT_TRUE);
											else
												pInputElem->put_checked (VARIANT_FALSE);
										}
										if (bChangeValue)
										{
											CString sTemp (sNewValue);
											BSTR bstrNewValue = sTemp.AllocSysString ();
											pInputElem->put_value (bstrNewValue);
											SysFreeString (bstrNewValue);
										}
										if (bSelect)
											pInputElem->select ();

										if (bClick)
											pElem->click ();
									}
									pInputElem->Release ();
								}
							}
							pElem->Release ();
						}
						pElemDispatch->Release ();
					}		
				}
				pColl->Release ();
			}
			pHtmlDoc->Release();
		}
		pHtmlDocDispatch->Release ();
	}

	if (bSearch == false)
		return true;
	
	return false;
}
Пример #28
0
bool CMyInternetExplorer::FindElement (bool bExactMatch, bool bWildcardMatch, bool bCaseSensitive, bool bClick,
									   bool bTagName, bool bOuterHTML, bool bInnerHTML, bool bTooltip,
									   LPCTSTR sTagNameOrg, LPCTSTR sOuterHTMLOrg, LPCTSTR sInnerHTMLOrg, LPCTSTR sTooltipOrg, 
									   CString & sRetTagName, CString & sRetOuterHTML, CString & sRetInnerHTML, CString & sRetTooltip)
{
	ASSERT (m_pWebBrowser != NULL);
	if (m_pWebBrowser == NULL)
		return false;
	
	HRESULT hr;
	IDispatch* pHtmlDocDispatch = NULL;
	IHTMLDocument2 * pHtmlDoc = NULL;
	bool bSearch = true;

	// Retrieve the document object.
	hr = m_pWebBrowser->get_Document (&pHtmlDocDispatch);
	if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
	{
		hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2,  (void**)&pHtmlDoc);
		if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
		{
			IHTMLElementCollection* pColl = NULL;
			hr = pHtmlDoc->get_all (&pColl);

			if (SUCCEEDED (hr) && (pColl != NULL))
			{
				CString sTagName (sTagNameOrg), sOuterHTML (sOuterHTMLOrg), sInnerHTML (sInnerHTMLOrg), sTooltip (sTooltipOrg);
				if (!bCaseSensitive)
				{
					sTagName.MakeLower ();
					sOuterHTML.MakeLower ();
					sInnerHTML.MakeLower ();
					sTooltip.MakeLower ();
				}

				// Obtained the Anchor Collection...
				long nLength = 0;
				pColl->get_length (&nLength);
				
				for (int i = 0; i < nLength && bSearch; i++)
				{
					COleVariant vIdx ((long)i, VT_I4);
					
					IDispatch* pElemDispatch = NULL;
					IHTMLElement * pElem = NULL;
					
					hr = pColl->item (vIdx, vIdx, &pElemDispatch);
					
					if (SUCCEEDED (hr) && (pElemDispatch != NULL))
					{
						hr = pElemDispatch->QueryInterface(IID_IHTMLElement, (void**)&pElem);
						
						if (SUCCEEDED (hr) && (pElem != NULL))
						{
							BSTR bstrTagName, bstrOuterHTML, bstrInnerHTML, bstrTooltip;
							CString sTempTagName, sTempOuterHTML, sTempInnerHTML, sTempTooltip;
							if (!FAILED (pElem->get_tagName (&bstrTagName)))
							{
								sTempTagName = bstrTagName;
								SysFreeString (bstrTagName);
							}
							if (!FAILED (pElem->get_outerHTML (&bstrOuterHTML)))
							{
								sTempOuterHTML = bstrOuterHTML;
								SysFreeString (bstrOuterHTML);
							}
							if (!FAILED (pElem->get_innerHTML (&bstrInnerHTML)))
							{
								sTempInnerHTML = bstrInnerHTML;
								SysFreeString (bstrInnerHTML);
							}
							if (!FAILED (pElem->get_title (&bstrTooltip)))
							{
								sTempTooltip = bstrTooltip;
								SysFreeString (bstrTooltip);
							}
							
							sRetTagName = sTempTagName;
							sRetOuterHTML = sTempOuterHTML;
							sRetInnerHTML = sTempInnerHTML;
							sRetTooltip = sTempTooltip;

							if (!bCaseSensitive)
							{
								sTempTagName.MakeLower ();
								sTempOuterHTML.MakeLower ();
								sTempInnerHTML.MakeLower ();
								sTempTooltip.MakeLower ();
							}

							// Do the comparison here!
							bool bMatches = true;
							if (bMatches && bTagName)
							{
								if (bExactMatch)
								{
									if (sTempTagName != sTagName)
										bMatches = false;
								}
								else if (bWildcardMatch)
								{
									if (bCaseSensitive)
									{
										if (!StringHelper::WildcardCompareNoCase (sTagName, sTempTagName))
											bMatches = false;
									}
									else
									{
										if (!StringHelper::WildcardCompare (sTagName, sTempTagName))
											bMatches = false;
									}
								}
								// Just locate the text inside!
								else
								{
									if (sTempTagName.Find (sTagName) == -1)
										bMatches = false;
								}
							}
							if (bMatches && bOuterHTML)
							{
								if (bExactMatch)
								{
									if (sTempOuterHTML != sOuterHTML)
										bMatches = false;
								}
								else if (bWildcardMatch)
								{
									if (bCaseSensitive)
									{
										if (!StringHelper::WildcardCompareNoCase (sOuterHTML, sTempOuterHTML))
											bMatches = false;
									}
									else
									{
										if (!StringHelper::WildcardCompare (sOuterHTML, sTempOuterHTML))
											bMatches = false;
									}
								}
								// Just locate the text inside!
								else
								{
									if (sTempOuterHTML.Find (sOuterHTML) == -1)
										bMatches = false;
								}
							}
							if (bMatches && bInnerHTML)
							{
								if (bExactMatch)
								{
									if (sTempInnerHTML != sInnerHTML)
										bMatches = false;
								}
								else if (bWildcardMatch)
								{
									if (bCaseSensitive)
									{
										if (!StringHelper::WildcardCompareNoCase (sInnerHTML, sTempInnerHTML))
											bMatches = false;
									}
									else
									{
										if (!StringHelper::WildcardCompare (sInnerHTML, sTempInnerHTML))
											bMatches = false;
									}
								}
								// Just locate the text inside!
								else
								{
									if (sTempInnerHTML.Find (sInnerHTML) == -1)
										bMatches = false;
								}
							}
							if (bMatches && bTooltip)
							{
								if (bExactMatch)
								{
									if (sTempTooltip != sTooltip)
										bMatches = false;
								}
								else if (bWildcardMatch)
								{
									if (bCaseSensitive)
									{
										if (!StringHelper::WildcardCompareNoCase (sTooltip, sTempTooltip))
											bMatches = false;
									}
									else
									{
										if (!StringHelper::WildcardCompare (sTooltip, sTempTooltip))
											bMatches = false;
									}
								}
								// Just locate the text inside!
								else
								{
									if (sTempTooltip.Find (sTooltip) == -1)
										bMatches = false;
								}
							}
							// Done with the comparisons!
							if (bMatches)
							{
								//if (IDCANCEL == AfxMessageBox (_T ("Tag: ") + sTempTagName + _T ("\r\nOuter: ") + sTempOuterHTML + _T ("\r\nInner: ") + sTempInnerHTML + _T ("\r\nTooltip: ") + sTempTooltip, MB_OKCANCEL))
								//	bSearch = false;

								// No need to search more!
								bSearch = false;
								if (bClick)
									pElem->click ();
							}
							pElem->Release ();
						}
						pElemDispatch->Release ();
					}		
				}
				pColl->Release ();
			}
			pHtmlDoc->Release();
		}
		pHtmlDocDispatch->Release ();
	}

	sRetTagName.Empty ();
	sRetOuterHTML.Empty ();
	sRetInnerHTML.Empty ();
	sRetTooltip.Empty ();
	
	if (bSearch == false)
		return true;
	
	return false;
}
Пример #29
0
IHTMLElement* FindElement(IHTMLDocument2* pDoc2, LPCTSTR elementId, LPCTSTR elementName)
{
	USES_CONVERSION;
	HRESULT hr;

	//Enumerate the HTML elements
    IHTMLElementCollection* pColl = NULL;
    hr = pDoc2->get_all( &pColl );
    if (hr == S_OK && pColl != NULL)
    {
		LONG celem;
        pColl->get_length( &celem );

		 //Loop through each elment
        for ( int i=0; i< celem; i++ )
        {
            VARIANT varIndex;
            varIndex.vt = VT_UINT;
            varIndex.lVal = i;
            VARIANT var2;
            VariantInit( &var2 );

            IDispatch* pDisp; 

            hr = pColl->item( varIndex, var2, &pDisp );//Get an element

			if ( hr == S_OK )
            {
                IHTMLElement* pElem;
				//Ask for an HTMLElemnt interface
                hr = pDisp->QueryInterface(IID_IHTMLElement, (void **)&pElem);

				if ( hr == S_OK )
                {
					if(elementId != NULL) //find element by Id
					{
						BSTR bstr;
						//Get the id of the element
						pElem->get_id(&bstr);
	                   					
						LPCTSTR id = OLE2T(bstr);

						if(_tcscmp(id, elementId))
						{
							return pElem;						
						}
					}
					else if(elementName != NULL) //find element by Name
					{
						IHTMLInputButtonElement* pButton;
                        hr = pDisp->QueryInterface(IID_IHTMLInputButtonElement,(void **)&pButton);
                        if ( hr == S_OK )
                        {
							BSTR bstr;
							//Get the name of the element
							pButton->get_name(&bstr);
		                   					
							LPCTSTR name = OLE2T(bstr);

							if(_tcscmp(name, elementName))
							{
								return pElem;						
							}
						}
					}
					
					pElem->Release();
				}
			}			
		}

		pColl->Release();
	}

	return NULL;
}
Пример #30
0
bool CMyInternetExplorer::FindOption (bool bClick, 
									  bool bValue, bool bText,
									  LPCTSTR sValue, LPCTSTR sText)
{
	ASSERT (m_pWebBrowser != NULL);
	if (m_pWebBrowser == NULL)
		return false;
	
	HRESULT hr;
	IDispatch* pHtmlDocDispatch = NULL;
	IHTMLDocument2 * pHtmlDoc = NULL;
	bool bSearch = true;

	// Retrieve the document object.
	hr = m_pWebBrowser->get_Document (&pHtmlDocDispatch);
	if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
	{
		hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2,  (void**)&pHtmlDoc);
		if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
		{
			IHTMLElementCollection* pColl = NULL;
			hr = pHtmlDoc->get_all (&pColl);

			if (SUCCEEDED (hr) && (pColl != NULL))
			{
				// Obtained the Anchor Collection...
				long nLength = 0;
				pColl->get_length (&nLength);
				
				for (int i = 0; i < nLength && bSearch; i++)
				{
					COleVariant vIdx ((long)i, VT_I4);
					
					IDispatch* pElemDispatch = NULL;
					IHTMLElement * pElem = NULL;
					
					hr = pColl->item (vIdx, vIdx, &pElemDispatch);
					
					if (SUCCEEDED (hr) && (pElemDispatch != NULL))
					{
						hr = pElemDispatch->QueryInterface(IID_IHTMLElement, (void**)&pElem);
						
						if (SUCCEEDED (hr) && (pElem != NULL))
						{
							BSTR bstrTagName;
							CString sTempTagName;
							if (!FAILED (pElem->get_tagName (&bstrTagName)))
							{
								sTempTagName = bstrTagName;
								sTempTagName.MakeLower ();
								SysFreeString (bstrTagName);
							}

							if (sTempTagName == _T ("option"))
							{
								IHTMLOptionElement * pOption = NULL;
								hr = pElemDispatch->QueryInterface (IID_IHTMLOptionElement, (void**)&pOption);
								
								if (SUCCEEDED (hr) && (pOption != NULL))
								{
									BSTR bstrValue, bstrText;
									CString sTempValue, sTempText;
									
									if (!FAILED (pOption->get_value (&bstrValue)))
									{
										sTempValue = bstrValue;
										SysFreeString (bstrValue);
									}
									if (!FAILED (pOption->get_text (&bstrText)))
									{
										sTempText = bstrText;
										SysFreeString (bstrText);
									}
									
									//if (IDCANCEL == AfxMessageBox (_T ("Value: ") + sTempValue + _T ("\r\nText: ") + sTempText, MB_OKCANCEL))
									//	bSearch = false;

									// Do the comparison here!
									bool bMatches = true;
									if (bMatches && bValue)
									{
										if (!StringHelper::WildcardCompareNoCase (sValue, sTempValue))
											bMatches = false;
									}
									if (bMatches && bText)
									{
										if (!StringHelper::WildcardCompareNoCase (sText, sTempText))
											bMatches = false;
									}
									
									if (bMatches)
									{
										// No need to search more!
										bSearch = false;
										
										pOption->put_selected (VARIANT_TRUE);
										if (bClick)
											pElem->click ();
									}
									pOption->Release ();
								}
							}
							pElem->Release ();
						}
						pElemDispatch->Release ();
					}		
				}
				pColl->Release ();
			}
			pHtmlDoc->Release();
		}
		pHtmlDocDispatch->Release ();
	}
	
	if (bSearch == false)
		return true;

	return false;
}