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

  • 主题发起人 wjw842009
  • 开始时间
W

wjw842009

Unregistered / Unconfirmed
GUEST, unregistred user!
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;



謝謝回複!!!
 
spDisp可能=nil
 
谢谢答复!!!但调试时指针不为空。
 
begin

spDisp:=spDoc.Script;
spWin:= spDisp as IHTMLWindow2;//改成这样,如果报错了,就说明spDisp不支持IHTMLWindow2接口。
result:=spWin.document;

end;
 
谢谢楼上,没有出错了,但现在的问题是,不能获取密码框 的内容,能帮我改下上面的代码吗?真的不好意思,麻烦各位!!!非常非常谢谢!!!
 
再帮忙顶下,谢谢!!!
 
希望各位牛人 帮我改下这几行代码,谢谢!!!
 
你的代码里面是就一个if,只能获取第一个元素,你的代码需要放在循环里面。我博客上刚刚发了个枚举IHTMLDocument2上所有Image的代码,可供你参考:
http://blog.sina.com.cn/u/5591c0790100057k
 
框架内的地址跟当前页面的地址不在同一个域就会出错,最好加上 try...except...end
 
谢谢楼上,我去看下,错误 是没有出现,主要是捕获不到密码框内容、
 
还是不解,我对这个一点不知,请问有没有这方面的书籍。或者如何获取ie中的网页表单中的数据。
 
顶部