-

- 加为好友
- 发送私信
- 在线聊天
-
jjqingwa
- 等级:

- 可用分等级:
- 总技术分:
- 总技术分排名:
- 结帖率:
|
| 发表于:2008-08-19 20:34:17 楼主 |
IHTMLDocument2获取内嵌框架问题,下断跟踪发现使用get_frame获取到的值为空~这个问题头痛了几天~一直没解决~望各位牛人帮小弟解惑~具体代码如下(希望各位牛人指出错误之处及更改方法,小弟感激不尽): #include "stdio.h" #include "string.h" #include "windows.h" #include "mshtml.h" #include "atlbase.h" #include "oleacc.h" void GetFrame(IHTMLDocument2 *pIHTMLDocument2) { if(!pIHTMLDocument2) return; HRESULT hr; CComPtr <IHTMLFramesCollection2> spFramesCollection2; pIHTMLDocument2->get_frames(&spFramesCollection2); long nFrameCount=0; hr=spFramesCollection2->get_length(&nFrameCount); if(FAILED(hr)||0==nFrameCount) return; for(long i=0;i <nFrameCount;i++) { CComVariant vDispWin2; hr=spFramesCollection2->item(&CComVariant(i),&vDispWin2); if(FAILED(hr)) continue; CComQIPtr <IHTMLWindow2> spWin2=vDispWin2.pdispVal; if(!spWin2) continue; CComPtr <IHTMLDocument2> spDoc2; spWin2->get_document(&spDoc2); } } IHTMLDocument2 *OnGetDocInterface(HWND hWnd) { IHTMLDocument2* pDoc2=NULL; CComPtr <IHTMLDocument2> spDoc; CoInitialize( NULL ); // EXPlicitly load MSAA so we know if it's installed HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") ); if ( hInst != NULL ) { if ( hWnd != NULL ) { HWND hWndChild=NULL; // Get 1st document window hWndChild=hWnd; if ( hWndChild ) { LRESULT lRes; UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") ); ::SendMessageTimeout( hWndChild, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes ); LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, _T("ObjectFromLresult") ); if ( pfObjectFromLresult != NULL ) { HRESULT hr; hr = (*pfObjectFromLresult)( lRes, IID_IHTMLDocument, 0, (void**)&spDoc ); if ( SUCCEEDED(hr) ) { CComPtr <IDispatch> spDisp; CComQIPtr <IHTMLWindow2> spWin; spDoc->get_Script( &spDisp ); spWin = spDisp; spWin->get_document( &pDoc2 ); } } } // else document not ready } // else Internet EXPlorer is not running ::FreeLibrary( hInst ); } // else Active Accessibility is not installed CoUninitialize(); return pDoc2; } BOOL Find() { HWND hwnd; char ClassName[255]; hwnd=GetForegroundWindow(); GetClassName(hwnd,ClassName,255); if(strcmp(ClassName,"IEFrame")==0) { hwnd=FindWindowEx(hwnd,NULL,"Shell DocObject View",NULL); hwnd=FindWindowEx(hwnd,NULL,"Internet Explorer_Server",NULL); GetFrame(OnGetDocInterface(hwnd)); } return TRUE; } void main() { while(TRUE) { Find(); } } |
|
|
|
10
修改
删除
举报
引用
回复
| |