请教如何用DELPHI做个监听程序判断机器是否打开某个网页呢?比如做个小监听服务器程序时时循环判断某个网页如(www.google.cn)已经打开了呢?不用WebBrowser实现!?

解决方案 »

  1.   

    procedure TForm1.Button2Click(Sender: TObject);
    const
      maxx = 30;
    var
      ShellWindow: IShellWindows;
      nCount: integer;
      spDisp: IDispatch;
      i: integer;
      vi: OleVariant;
      IE1: IWebBrowser2;
    begin
     listbox1.clear;
      ShellWindow := CoShellWindows.Create;
      nCount := ShellWindow.Count;
      for i := 0 to nCount - 1 do
      begin
        vi := i;
        try
          spDisp := ShellWindow.Item(vi);
        except
          exit
        end;
        if (spDisp <> nil) then
        begin
          try
            spDisp.QueryInterface(iWebBrowser2, IE1);
          except
            on EAccessViolation do
            begin
              exit
            end;
          end;
          if (IE1 <> nil) then
          begin
          if  copy(IE1.Get_LocationURL(),1,4)='http' then
          showmessage('已打开IE');
           listbox1.items.add(IE1.Get_LocationURL());
          end;
        end;
      end;
      deletefile(extractfilepath(paramstr(0)) + 'Address.d' + inttostr(maxx));
      for i := maxx - 1 downto 0 do
       renamefile(extractfilepath(paramstr(0)) + 'Address.d' + format('%.2d', [i]), 'Address.d' + format('%.2d', [i + 1]));
      listbox1.items.savetofile(extractfilepath(paramstr(0)) + 'Address.d00');