關於IHTMLDocument2代碼出錯?不知道錯在哪裏,謝謝回複!!!

wjw842008 2006-09-10 09:09:27
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,SHDocVw,Activex,MSHTML,OleCtrls;

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


function GetDocInterface(hwnd:THandle):IHtmlDocument2;
var
hInst: THandle;
hr:HResult;
lRes:Cardinal;
MSG: Integer;
spDisp:IDispatch;
spDoc:IHTMLDocument;
pDoc2:IHTMLDocument2;
spWin:IHTMLWindow2;
ObjectFromLresult: TObjectFromLresult;
begin
hInst := LoadLibrary('Oleacc.dll');
if hInst=0 then exit;
@ObjectFromLresult := GetProcAddress(hInst, 'ObjectFromLresult');
if @ObjectFromLresult <> nil then begin
try
MSG := RegisterWindowMessage('WM_HTML_GETOBJECT');
SendMessageTimeOut(Hwnd, MSG, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes);
hr:= ObjectFromLresult(lRes, IHTMLDocument2, 0, spDoc);
if SUCCEEDED(hr) then
begin
spDisp:=spDoc.Script;
spWin:=IHTMLWindow2(spDisp);
result:=spWin.document; //這裏出錯,請問錯在哪裏
end;
finally
FreeLibrary(hInst);
end;
end;
end;

procedure GetPassword(pdoc2:IHTMLDocument2;pt:TPoint);
var
ltype:string;
pwd:string;
pElement:IHTMLElement;
pPwdElement:IHTMLInputTextElement;
hr:HRESULT;
begin
if (pDoc2=Nil) then exit;
pElement:=pDoc2.elementFromPoint(pt.x,pt.y);
hr:=pElement.QueryInterface(IID_IHTMLInputTextElement,pPwdElement);
if(SUCCEEDED(hr)) then
begin
if (pPwdElement.type_='password') and (pPwdElement.value<>'') then
begin
showmessage(pPwdElement.value);
end;
end;
end;



procedure TForm1.Timer1Timer(Sender: TObject);
var
pt:TPoint;
handle:Thandle;
buffer:PChar;
strbuffer:string;
begin
GetCursorPos(pt);
handle:=WindowFromPoint(pt);
if handle<>0 then
begin
GetClassName(handle,buffer,100);
strbuffer:=strpas(buffer);
if strbuffer='Internet Explorer_Server' then
begin
pt:=ScreenToClient(pt);
GetPassword(GetDocInterface(handle),pt);
end;
end;

end;


謝謝回複!!!
...全文
155 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
王集鹄 2006-09-11
  • 打赏
  • 举报
回复
function GetDocInterface(hwnd:THandle):IHtmlDocument2;
var
hInst: THandle;
hr:HResult;
lRes:Cardinal;
MSG: Integer;
spDisp:IDispatch;
spDoc:IHTMLDocument;
pDoc2:IHTMLDocument2;
spWin:IHTMLWindow2;
ObjectFromLresult: TObjectFromLresult;
begin
hInst := LoadLibrary('Oleacc.dll');
if hInst=0 then exit;
@ObjectFromLresult := GetProcAddress(hInst, 'ObjectFromLresult');
if @ObjectFromLresult <> nil then begin
try
MSG := RegisterWindowMessage('WM_HTML_GETOBJECT');
SendMessageTimeOut(Hwnd, MSG, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes);
hr:= ObjectFromLresult(lRes, IHTMLDocument2, 0, Result); //<<<<<
if not SUCCEEDED(hr) then Result := nil;
finally
FreeLibrary(hInst);
end;
end;
end;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧