3,245
社区成员
发帖
与我相关
我的任务
分享
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;
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 的接口指针
}
}