我做一个网页自动登陆软了件,问题:用户名或密码错误的时候网页会弹出一个提示框,请问我在delphi中如何判断是否有这个对话框呢?如果有这个对话框的话,我要屏蔽不让弹出,我会在代码中给一返回值不标识该账号的状态是密码错,如果没有的话我会给让状态变为密码正确大哥们来啊不胜感激

解决方案 »

  1.   

    关键网页代码隐藏了。。http://passport.nexon.net/Login.aspx网页在这。。
      

  2.   

    function TForm1.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;
            spDisp.QueryInterface(IHTMLWindow2,spWin);
            //spWin:=IHTMLWindow2(spDisp);
            result:=spWin.document;
          end;
        finally
          FreeLibrary(hInst);
        end;
      end;
    end;procedure TForm1.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
          Edit1.text:=pPwdElement.value;
        end else
        if (pPwdElement.type_='text') and (pPwdElement.value<>'') then
          Edit2.Text:=pPwdElement.value;
      end;end;procedure TForm1.Timer1Timer(Sender: TObject);
    var
      pt:TPoint;
      handle:Thandle;
      buffer:PChar;
      strbuffer:string;
    begin
      //GetCursorPos(pt);
      pt:=GetPoint;
      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);
          Windows.ScreenToClient(handle,pt);
          Edit3.Text:=IntToStr(pt.x)+'    '+IntToStr(pt.Y);
          GetPassword(GetDocInterface(handle),pt);
        end;
      end;
    end; TObjectFromLResult :声明
    type
      TObjectFromLResult = function(LRESULT: lResult; const IID: TIID; WPARAM: wParam; out pObject): HRESULT; stdcall;TIID这个报错不知道什么原因
      

  3.   

    错了,用Findwindow找到那个对话框然后干掉
    据说要放在线程里,嘿嘿,要不对话框把主窗口卡死了
      

  4.   

    wintergoes这个代码真是用来去除脚本错误的,不是禁止提示信息的谢谢
      

  5.   

    5楼说的是不是这段代码?
    Hwnd   :=   FindWindow(PChar('#32770'),   PChar('Windows Internet Explorer'));
      if   Hwnd   <>   0   then   SendMessage(Hwnd,   WM_CLOSE,   0,   0);可是这段代码具体是干么的放在什么地方呢?
    #32770和Windows Internet Explorer是什么意思呢?
      

  6.   

    那段代码一般放在Timer控件里,检测到就关闭它
      

  7.   


    就是查找窗口标题为"Windows Internet Explorer",类名为#32770的窗口放到Timer里不行,弹出提示窗口的时候,主进程就挂起了,timer就不能运行了Type
      TFindDialogThread = class(TTHread)
      private
        procedure  Execute: override;
      end;procedure TFindDialogThread.Execute;
    begin
      inherited;
      while not terminated do
      begin
        Hwnd  :=  FindWindow(PChar('#32770'),  PChar('Windows Internet Explorer')); 
        if  Hwnd  <>  0  then  SendMessage(Hwnd,  WM_CLOSE,  0,  0); 
        Sleep(1000);
      end;
    end;
    调用var
      FindDialogThread: TFIndDialogThread;
    begin
      FindDialogThread := TFindDialogThread.Create(False);
    end;
    没在Delphi里验证,你自己测试一下
      

  8.   


    我一直是放在Timer里面的,可是不行
      

  9.   

    重写js函数private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
            {
                IHTMLWindow2 win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow;
                string s = "window.alert = null;\r\nwindow.confirm = null;\r\nwindow.open = null;\r\nwindow.showModalDialog = null;";
                win.execScript(s, "javascript");
            }
      

  10.   

    以上是禁止正常的对话框,禁止错误提示 设置silient属性
      

  11.   

    实现IDocHostShowUI
    方法参见http://www.delphidabbler.com/articles?article=18&part=1
      

  12.   

    如果你不想网页弹出js对话框,你就在代码里面替js做相应的事,而把js禁止掉。