下午等着开会,无聊又翻出DLL代码来,上次由于VCExpress不支持ATL,导致程序开发停止。研究个作弊的法子,终于可以继续写下去了。
下面是今天反复尝试后的代码,可以获取Lingos结果窗口的显式了。很乱,参考都不建议,仅仅做个记录。
1#include <mshtml.h>
2#include <atlbase.h>
3#include <oleacc.h>
4#include <tchar.h>
5
6BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
7{
8 TCHAR buf[100];
9
10 ::GetClassName( hwnd, (LPTSTR)&buf, 100 );
11 if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 )
12 {
13 *(HWND*)lParam = hwnd;
14 return FALSE;
15 }
16 else
17 return TRUE;
18};
19
20//You can store the interface pointer in a member variable
21//for easier access
22void OnGetDocInterface(HWND hWnd)
23{
24 CoInitialize( NULL );
25
26 // Explicitly load MSAA so we know if it's installed
27 HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
28 if ( hInst != NULL )
29 {
30 if ( hWnd != NULL )
31 {
32 HWND hWndChild=NULL;
33 // Get 1st document window
34 ::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild );
35 if ( hWndChild )
36 {
37 CComPtr<IHTMLDocument2> spDoc;
38 LRESULT lRes;
39
40 UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
41 ::SendMessageTimeout( hWndChild, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes );
42
43 LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress(hInst, ("ObjectFromLresult"));
44 if ( pfObjectFromLresult != NULL )
45 {
46 HRESULT hr;
47 hr = (*pfObjectFromLresult)( lRes, IID_IHTMLDocument, 0, (void**)&spDoc );
48 if ( SUCCEEDED(hr) )
49 {
50 IDispatch *pDisp;
51 IHTMLWindow2 *pWin;
52 spDoc->get_Script(&pDisp);
53 pDisp->QueryInterface(IID_IHTMLWindow2, (void **)&pWin);
54 //pDisp->Release();
55 IHTMLDocument2* pDoc = NULL;
56 pWin->get_document(&pDoc);
57 //pWin->Release();
58
59 //VARIANT v;
60 //v.vt = VT_BSTR;
61 //v.bstrVal = _T("FF0000");
62 /**/////spDoc->put_bgColor(v);// CComVariant("red") );
63 ////pDoc->get_bgColor(&v);
64 //pDoc->put_bgColor(v);
65
66 IHTMLElement* p = NULL;
67 pDoc->get_body(&p);
68 BSTR str;
69 p->get_innerText(&str);
70 BSTR html;
71 p->get_innerHTML(&html);
72
73 VARIANT m;
74 m = v;
75 }
76 }
77 } // else document not ready
78 } // else Internet Explorer is not running
79 ::FreeLibrary( hInst );
80 } // else Active Accessibility is not installed
81 CoUninitialize();
82} 这样,关于Lingos取结果的问题中的关键两个问题都解决了,可以着手写代码。嘿嘿,不知道还有没有兴趣继续下去~