• 得到别的程序的窗口句柄,改变窗口标题,要改变窗口文本框内容程序如下


    得到别的程序的窗口句柄,改变窗口标题,要改变窗口文本框内容程序如下

    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.
    View Code
  • 相关阅读:
    【Go学习笔记】 string转Map 和 Map嵌套取值 和 interface转string
    【Go 学习】Go 正则类似Python findall()方法
    【Go学习】Go mod 包管理
    构建之法阅读笔记(四)
    nltk安装配置以及语料库的安装配置
    机器学习KNN算法实现新闻文本分类思路总结
    KNN算法源代码
    构建之法阅读笔记(三)
    jupyter反爬虫
    python多条件模糊查询
  • 原文地址:https://www.cnblogs.com/blogpro/p/11453683.html
Copyright © 2020-2023  润新知