我刚好最近作了一个,发给你
他获得当前窗口CartID输入框的内容
var ShellWindow: IShellWindows;
nCount: integer;
spDisp: IDispatch;
i,j: integer;
vi: OleVariant;
IE1: IWebBrowser2;
IDoc1: IHTMLDocument2;
iELC : IHTMLElementCollection
HtmlInputEle : IHTMLInputElement;
IEHandle:HWND;
begin
//获得当前窗口句柄
IEHandle:=GetActiveWindow;
//遍历当前IE窗口
ShellWindow := CoShellWindows.Create;
nCount := ShellWindow.Count;
for i := 0 to nCount - 1 do
begin
vi := i;
spDisp := ShellWindow.Item(vi);
if spDisp = nil then continue;
spDisp.QueryInterface( iWebBrowser2, IE1 );
if IE1 = nil then continue;
if IE1.Get_HWND<>IEHandle then continue;
IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);
if iDoc1 <> nil then
begin
memo1.lines.add(idoc1.url);
ielc:=idoc1.Get_all;
for j:=0 to ielc.length-1 do
begin
Application.ProcessMessages;
spDisp := ielc.item(J, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLInputElement ,HtmlInputEle))then
with HtmlInputEle do
if htmlinputele.name='CartID' then
memo1.lines.add(htmlinputele.value);
end;
end;
end;
end;