Exemplo n.º 1
0
wb2 GetIE(HWND w)
{
	SHDocVw::IShellWindowsPtr shp; 
	shp.CreateInstance(__uuidof(SHDocVw::ShellWindows)); 

	int count = shp->GetCount();

	IDispatchPtr spDisp;

	// ---- get the browsers 
	for (long i = 0; i < count; i++) {
		_variant_t va(i, VT_I4);
		spDisp = shp->Item(va);

		SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
		if (spBrowser != NULL)
		{
			HWND hw;

			try {
				hw = (HWND)spBrowser->GetHWND();
			} catch ( ... ) {
				hw = NULL;
			}
			if (hw == w) return spBrowser;

		}
	}

	return NULL;
}
Exemplo n.º 2
0
HRESULT fsShellBrowsersEvents::Attach(SHDocVw::IShellWindowsPtr& spSHWnds)
{
	if (m_bDetaching)
		return S_FALSE;

	if (is_Attached ())
		Detach ();

	LONG cItems = spSHWnds->GetCount ();
	HRESULT hr;

	
	for (LONG i = 0; i < cItems; i++)
	{
		try 
		{
			IDispatchPtr spDisp;
			_variant_t va (i, VT_I4);
		
			spDisp = spSHWnds->Item (va);

			SHDocVw::IWebBrowser2Ptr spBrowser (spDisp);

			if (spBrowser == NULL)
				continue;

			
			fsShellBrowsersEvents* pBrowser = new fsShellBrowsersEvents;
		
			hr = pBrowser->Attach (spBrowser); 

			if (FAILED (hr))
			{
				delete pBrowser;
				return hr;
			}

			pBrowser->SetEventFunc (m_pfnEvents, m_lpEventsParam);

			m_vBrowsers.add (pBrowser);
		}
		catch (const std::exception& ex)
		{
			ASSERT (FALSE);
			vmsLogger::WriteLog("fsShellBrowsersEvents::Attach " + std::string(ex.what()));
		}
		catch (...)
		{
			ASSERT (FALSE);
			vmsLogger::WriteLog("fsShellBrowsersEvents::Attach unknown exception");
		}
	}
	
	return S_OK;
}
Exemplo n.º 3
0
HRESULT fsShellBrowsersEvents::Attach(SHDocVw::IShellWindowsPtr& spSHWnds)
{
	if (m_bDetaching)
		return S_FALSE;

	if (is_Attached ())
		Detach ();

	LONG cItems = spSHWnds->GetCount ();
	HRESULT hr;

	
	for (LONG i = 0; i < cItems; i++)
	{
		try {
		IDispatchPtr spDisp;
		_variant_t va (i, VT_I4);
		
		spDisp = spSHWnds->Item (va);

		SHDocVw::IWebBrowser2Ptr spBrowser (spDisp);

		if (spBrowser == NULL)
			continue;

		
		fsShellBrowsersEvents* pBrowser = new fsShellBrowsersEvents;
		
		hr = pBrowser->Attach (spBrowser);

		if (FAILED (hr))
		{
			delete pBrowser;
			return hr;
		}

		pBrowser->SetEventFunc (m_pfnEvents, m_lpEventsParam);

		m_vBrowsers.add (pBrowser);
		}
		catch (...) {}
	}
	
	return S_OK;
}
Exemplo n.º 4
0
bool CMyInternetExplorer::FindUsingTitle (const CString & sTitleToSearch)
{
	if (m_pWebBrowser != NULL)
	{
		m_pWebBrowser->Release ();
		m_pWebBrowser = NULL;
	}

	HRESULT hr;
	SHDocVw::IShellWindowsPtr spSHWinds; 
	hr = spSHWinds.CreateInstance (__uuidof(SHDocVw::ShellWindows)); 
	
	if (FAILED (hr))
		return false;

	ASSERT (spSHWinds != NULL);
	
	long nCount = spSHWinds->GetCount ();

	IDispatchPtr spDisp;
	
	for (long i = 0; i < nCount; i++)
	{
		_variant_t va (i, VT_I4);
		spDisp = spSHWinds->Item (va);
		
		IWebBrowser2 * pWebBrowser = NULL;
		hr = spDisp.QueryInterface (IID_IWebBrowser2, & pWebBrowser);
		
		if (pWebBrowser != NULL)
		{
			HRESULT hr;
			IDispatch* pHtmlDocDispatch = NULL;
			IHTMLDocument2 * pHtmlDoc = NULL;
			
			// Retrieve the document object.
			hr = pWebBrowser->get_Document (&pHtmlDocDispatch);
			
			if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
			{
				// Query for IPersistStreamInit.
				hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2,  (void**)&pHtmlDoc);
				if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
				{
					CString sTitle;

					HWND hWnd = NULL;
					pWebBrowser->get_HWND ((long*)(&hWnd));
					if (::IsWindow (hWnd))
					{
						int nLen = ::GetWindowTextLength (hWnd);
						::GetWindowText (hWnd, sTitle.GetBufferSetLength (nLen), nLen + 1);
						sTitle.ReleaseBuffer ();
					}
					
					// If I cannot get the window title (should never happen though)
					// So, lets just use the title of the document
					if (sTitle.IsEmpty ())
					{
						BSTR bstrTitle;
						hr = pHtmlDoc->get_title (&bstrTitle);
						if (!FAILED (hr))
						{
							sTitle = bstrTitle;
							SysFreeString (bstrTitle); 
						}
					}
					
					if (StringHelper::WildcardCompareNoCase (sTitleToSearch, sTitle))
					{
						m_pWebBrowser = pWebBrowser;
						pHtmlDoc->Release ();
						pHtmlDocDispatch->Release ();
						// Exit the method safely!
						return true;
					}
					pHtmlDoc->Release();
				}
				pHtmlDocDispatch->Release ();
			}
			pWebBrowser->Release ();
		}
	}
	
	return false;
}