Internet Explorer_Server 获取文本的问题

每件事 2011-11-04 09:22:49
 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谢谢
...全文
103 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ysjyniiq 2011-11-06
  • 打赏
  • 举报
回复

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 的接口指针
}
}
fishion 2011-11-04
  • 打赏
  • 举报
回复
你用GetLastError看看是什么错误了
fishion 2011-11-04
  • 打赏
  • 举报
回复
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!!!
}

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧