??? 下午等著開會,無聊又翻出DLL代碼來,上次由于VCExpress不支持ATL,導致程序開發停止。研究個作弊的法子,終于可以繼續寫下去了。
??? 下面是今天反復嘗試后的代碼,可以獲取Lingos結果窗口的顯式了。很亂,參考都不建議,僅僅做個記錄。
?1
#include?<mshtml.h>
?2
#include?<atlbase.h>
?3
#include?<oleacc.h>
?4
#include?<tchar.h>
?5
?6
BOOL?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
22
void?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取結果的問題中的關鍵兩個問題都解決了,可以著手寫代碼。嘿嘿,不知道還有沒有興趣繼續下去~