Internet Explorer_Server 获取文本的问题
- C/C++ code
HWND m_hwnd; m_hwnd = ::FindWindow(NULL,"系统公告"); m_hwnd = FindWindowEx(m_hwnd, 0, "WTL_SplitterWindow", NULL); m_hwnd = FindWindowEx(m_hwnd, 0, "WTL_PaneContainer", NULL); m_hwnd = FindWindowEx(m_hwnd, 0, "AtlAxWin71", NULL); m_hwnd = FindWindowEx(m_hwnd, 0, "Shell Embedding", NULL); m_hwnd = FindWindowEx(m_hwnd, 0, "Shell DocObject View", NULL); m_hwnd = FindWindowEx(m_hwnd, 0, "Internet Explorer_Server", NULL); UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") ); LRESULT lRes; ::SendMessageTimeout( m_hwnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*) &lRes ); CComPtr < IHTMLDocument2 > spDoc; HRESULT hr = FALSE; hr=CoInitialize(0); hr = ::ObjectFromLresult ( lRes, IID_IHTMLDocument2, 0 , (LPVOID *) &spDoc ); if ( FAILED ( hr ) ) return TRUE;hr =-2147221008 ; 这里出错了。
上面获取“Internet Explorer_Server”的 句柄是对的,我用SPY++看了。
软件主要是想,获取Internet Explorer_Server上得文本数据。现在如果获得到了IHtmlDocument2接口,下面该怎么获得文本。
麻烦大家帮帮忙,O(∩_∩)O谢谢
[解决办法]
if(spDoc==NULL)
return S_FALSE;
IHTMLElementCollection* pIHTMLElementCollection=NULL;
if(spDoc-> get_all(&pIHTMLElementCollection)==S_OK)
{
long l;
pIHTMLElementCollection-> get_length(&l);
CComVariant v1,v2;
v1=(long)0;
v2=(long)0;
IDispatch* pDisp;
pIHTMLElementCollection-> item(v1,v2,&pDisp);
CComQIPtr <IHTMLElement, &IID_IHTMLElement> pHTMLElement(pDisp);
if(pHTMLElement!=NULL)
{
CComBSTR str;
pHTMLElement-> get_innerHTML(&str);//ok!!!
}
[解决办法]
你用GetLastError看看是什么错误了
[解决办法]
- C/C++ code
void FindFromShell() { CComPtr< IShellWindows > spShellWin; HRESULT hr = spShellWin.CoCreateInstance( CLSID_ShellWindows ); if ( FAILED( hr ) ) return; long nCount=0; spShellWin->get_Count(&nCount); // 取得浏览器实例个数 for(long i=0; i<nCount; i++) { CComPtr< IDispatch > spDisp; hr=spShellWin->Item(CComVariant( i ), &spDisp ); if ( FAILED( hr ) ) continue; CComQIPtr< IWebBrowser2 > spBrowser = spDisp; if ( !spBrowser ) continue; spDisp.Release(); hr = spBrowser->get_Document( &spDisp ); if ( FAILED ( hr ) ) continue; CComQIPtr< IHTMLDocument2 > spDoc = spDisp; if ( !spDoc ) continue; // 程序运行到此,已经找到了 IHTMLDocument2 的接口指针 }}