浏览器窗口的hwnd已得到,现在想知道如何取得浏览器中的文字?然后查找那些文字看是否有色情描述。

解决方案 »

  1.   

    给个例子,读取文字的,如果要读取代码,那你就将下面的outerText改为outerHTML,如果有问题就联系我:
    function GetIETextFromHWND(hWnd: HWND): String;
    var
      IE:IWebBrowser2;
    hInst: THandle;
    lRes: Cardinal;
    MSG: Integer;
    pDoc: IHTMLDocument2;
    ObjectFromLresult: TObjectFromLresult;
    ret:HRESULT;
    begin
    Result:='';
        ret:=S_OK;
        if (hWnd<=0) then
            exit;
    hInst := LoadLibrary('Oleacc.dll');
        if (hInst>0) then
        try
            @ObjectFromLresult := GetProcAddress(hInst, 'ObjectFromLresult');
            MSG := RegisterWindowMessage('WM_HTML_GETOBJECT');
            SendMessageTimeOut(hWnd, MSG, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes);
            ret := ObjectFromLresult(lRes, IID_IHTMLDocument2, 0, pDoc);
            if ret = S_OK then
            begin
                (pDoc.parentWindow as IServiceprovider).QueryService(IWebbrowserApp, IWebbrowser2,    IE);
                Result:=(IE.Document as IHTMLDocument2).body.innerText;
            end;
        finally
            FreeLibrary(hInst);
        end;
    end;
      

  2.   

    type
        TObjectFromLResult = function(LRESULT: lResult; const IID: TIID; WPARAM: wParam; out pObject): HRESULT; stdcall;