想通过DELPHI做个程序,可以将用户名和密码输入到另一软件(如QQ)的登录界面,并自动点击“登录”按钮登录,在正常登录后,模拟点击“QQ空间信息中心”,即那个黄色的星形,打开个人中心。也就是说通过自己编程实现操作QQ,该如何实现?

解决方案 »

  1.   

    FindWindow
     然后发送消息
      

  2.   

    FindWindowEx
    ********************************
    The FindWindowEx function retrieves a handle to a window whose class name and window name match the specified strings. The function searches child windows, beginning with the one following the specified child window. This function does not perform a case-sensitive search. 
    钮上的文字有可能是图片
      

  3.   

    以下是得到别的程序的窗口句柄,改变窗口标题,要改变窗口文本框内容程序如下:   
      unit   unit1;   
        
      interface   
        
      uses   
          Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,   Dialogs,   
          StdCtrls,   ComCtrls,   ExtCtrls;
        
      type   
          TForm1   =   class(TForm)   
              button2:   TButton;   
              ListBox1:   TListBox;   
              Button1:   TButton;   
              procedure   tutton2Click(Sender:   TObject);   
              procedure   Button1Click(Sender:   TObject);   
              procedure   Timer1Timer(Sender:   TObject);   
          private
              {   Private   declarations   }   
          public   
              {   Public   declarations   }   
          end;   
        
      var   
          Form1:   TForm1;   
        
      implementation     {$R   *.DFM}   
        
      function   GetText(Wnd   :   HWND)   :   string;   
      var   
          textlength   :   integer;   
          text   :   PChar;   
      begin   
          textlength:=SendMessage(Wnd,WM_GETTEXTLENGTH,0,0);   
          if   textlength=0   then   
              Result   :=   ''
          else   begin   
              getmem(text,textlength+1);   
              SendMessage(Wnd,WM_GETTEXT,textlength+1,Integer(text));   
              Result:=text;   
              freemem(text);   
          end;   
      end;   
      function   EnumWindowsProc   (Wnd:   HWND;   LParam:   LPARAM):   BOOL;   stdcall;   
      var   
          st:string;
      begin   
          Result   :=   True;   
          if   (IsWindowVisible(Wnd))   and   (GetWindowLong(Wnd,   GWL_HWNDPARENT)   =   0)   and   (GetWindowLong(Wnd,   GWL_EXSTYLE)   and   WS_EX_TOOLWINDOW   =   0)   then   begin   
              st:=GetText(Wnd);   
              Form1.Listbox1.items.add(st);   
          end;   
      end;   
      procedure   TForm1.tutton2Click(Sender:   TObject);   
      var
          Param   :   Longint;   
      begin   
          Form1.Listbox1.Clear;   
          Param   :=   0   ;   
          EnumWindows(@EnumWindowsProc   ,   Param);   
      end;     procedure   TForm1.Button1Click(Sender:   TObject);   
          function   EnumChildWindowsProc(hwnd:   Integer;   lparam:   Longint):Boolean;   stdcall;   
          var   
              buffer:   array[0..255]   of   Char;
          begin
              Result   :=   True;
              GetClassName(hwnd,buffer,256);
              if   StrPas(Buffer)='TEdit'   then
              begin
                  PInteger(lparam)^   :=   hwnd;
                  Result:=False;
              end;
          end;
      var
          Handle:   Integer;
          buffer:   Array[0..1023]   of   Char;
      begin
          Handle   :=   FindWindow(nil,pchar(Form1.listbox1.Items[listbox1.ItemIndex]));
          if   Handle<>0   then
          begin
              EnumChildWindows(Handle,@EnumChildWindowsProc,Integer(@Handle));
              SendMessage(Handle,WM_SETTEXT,0,Integer(pchar('你所需要填写的文本')));
          end;
      end;  end.
      

  4.   

    如果有句柄倒好办,无非就是sendmessage, 但是搞QQ却不容易,一般的方法都找不到上面的句柄
      

  5.   

    其实登录qq2009可以用以下的方法Dim Program 
    Program = "C:\Documents and Settings\QQ2009\QQ.exe" 
    Set WshShell=createobject("wscript.shell") 
    Set Exec=WshShell.Exec(Program) 
    WScript.Sleep 3000 
    WshShell.AppActivate "Idiot.CN" 
    WshShell.SendKeys "+{TAB}" 
    WshShell.SendKeys "qq号" 
    WScript.Sleep 200 
    WshShell.SendKeys "{TAB}" 
    WshShell.SendKeys "qq密码" 
    WScript.Sleep 200 
    WshShell.SendKeys "{ENTER}"
      

  6.   

    把上面的代码复制到记事本中,另存为qq2009.vbs
      

  7.   

    先用findwindow找到窗口,再用findwindowex找到窗口里面的组件,再sendmessage
    至于窗口和组件句柄,可以用VC自带的spy++这个工具来看看
      

  8.   

    思路是按楼上的来做的,是用SPY++查找的组件类名,但是根据此类名却找不到对应的组件,很奇怪。但我用此方法却可以找到记事本并修改记事本的内容
    [code=Delphi(Pascal)] 
    procedure TFrm_Main.Button6Click(Sender: TObject);
    var TxtHandle,ChildHandle:Thandle;
    begin
        TxtHandle:=FindWindow(nil,'无标题 - 记事本');
        if TxtHandle > 0 then
        begin
            ChildHandle:=FindWindowEx(TxtHandle,0,'Edit',nil);
            if ChildHandle > 0 then
            begin
                SendMessage(ChildHandle,WM_SETTEXT,0,Integer(Pchar('这是写入的内容')));
                EnableWindow(ChildHandle,False);
            end;
        end;end;
    [/code
      

  9.   

    是'TEdit' ,而不是你写的EDIT
      

  10.   

    回楼上的兄弟,的确是“Edit”,我在D7下测试通过
      

  11.   

    哦,那可能2个都行吧,我上面用TEDit测试也可以。学习了
      

  12.   


    但还是可以实现,而且不是用VBS的方法解决,因为VBS脚本不是在所有机器上都支持的。
    早些年有人写的“新欢乐时光病毒”,把VBS脚本运用的非常精僻,而且该病毒是VBS(相当于直接开源)格式,那段时间杀毒软件对VBS格式的文件都封杀了。
      

  13.   

    用FindWindow找到句柄,再用发消息的方法,
    接收的自己写消息方法来接收数据
      

  14.   

    空间中心,其实就和网页差不多,登陆->模拟点击。
    难道用delphi操作网页你不会?
     
      

  15.   

    利用Exescope找出这个程序的句柄  然后再定位按钮和登陆框
      

  16.   


    2009QQ窗口句柄不好弄
    总不能写一个Exescope程序出来吧?