比如说窗口的名字是 '123' 上边有个'确定',还有一个'取消'
如何能发送点击确定的命令?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
        ShellWindow: IShellWindows;
        ie :IWebBrowser2;
        i,j : Integer;
        V,vInput : OleVariant;
        sp:IDispatch;
        idoc:IHTMLDocument2;
        aInput :IHTMLInputButtonElement;
    begin
        ShellWindow := CoShellWindows.Create;
        for i:=0 to ShellWindow.Count-1 do
        begin
           V := i;
           sp := ShellWindow.Item(V);
           sp.QueryInterface(IWebBrowser2,ie);
           if ie<>nil then
           begin
            if ie.LocationURL='http://www.sohu.com'  then
            begin
                ie.Document.QueryInterface(IHTMLDocument2,idoc);
                if idoc<>nil then
                begin
                    for j:=0 to idoc.all.Length-1 do
                    begin
                        sp := idoc.all.item(j,varEmpty);
                        if SUCCEEDED(sp.QueryInterface(IHTMLInputButtonElement,aInput)) then
                        begin
                         if aInput.value='登录' then
                         begin
                            vInput := aInput;
                            vInput.Click;
                            Break;
                         end;
                        end;
                    end;
                end;
                Break;
            end;
           end;
        end;
    end; 
      

  2.   

    var
      w: HWND;
    begin
      w := FindWindow( nil, '123' );
      SendMessage( w, WM_COMMAND, 1, GetDlgItem(w, 1) );
    end;
      

  3.   

    靠 被楼上的抢先了 楼上的GG说的非常正确 用API
      

  4.   

    不错,不错。用API可以解决。