• delphi下实现控制其它窗体中的控件代码模板(delphi 7安装程序)


    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        ListBox1: TListBox;
        Button1: TButton;
        Button2: TButton;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    function GetAllHandle(hwnd: Integer; lparam: Longint): Boolean; stdcall; //回调函数
    var
      buffer: array[0..255] of Char;
      s: string;
      int: integer;
    begin
      Result := True;
      GetClassName(hwnd, buffer, 256);
      Form1.listbox1.items.add(format('%d', [hwnd, StrPas(Buffer)])); //写入窗口ListBox1中
    end;
    
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      handle: THandle;
    begin
      Handle := findWindow(nil, Pchar('Borland Delphi 7 Enterprise Edition - Installation Wizard')); //获得句柄
      if Handle <> 0 then
      begin
        EnumChildWindows(Handle, @GetAllHandle, Integer(@Handle));   // 枚举子窗体
    
        if Form1.ListBox1.Items.Count = 30 then   //这是破解delphi7的代码片段,由Timer控制这段代码运行,由于Delphi7安装时打开的窗口比较多,这里对窗口作一个简单的分析,判断要写入注册码的窗口内的控件句柄是否为31个(0——30)
        begin
          handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[3])); //给delphi7输入注册码
          SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('6KN6')));
          handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[5]));
          SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('PNWBQS')));
          handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[7]));
          SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('PB?ZUB')));
          handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[9]));
          SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('J8XW')));
          handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[11]));
          SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('YC7')));
          handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[13]));
          SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('24X')));
    
        end;
        
      end
      else
      ShowMessage('抱歉,没有找到!');
    
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    var
      s:string;
      BHandle:THandle;
    begin
      BHandle:=StrToInt(Edit1.Text);
     S:='你好吗?OK吗?';
     SendMessage(BHandle, WM_SETTEXT, 0, LongInt(lpstr(S)));  //写入文本字符
    end;
    
    end.
  • 相关阅读:
    删除前添加确认删除弹出框
    virtualbox 网络设置
    JavaScript跨域总结与解决办法
    分享一个ci 框架下取不到cookie的问题
    firebug console说明
    innodb 修改表共享空间为独立空间
    grunt 试用笔记
    apache TIME_WAIT解决办法
    负载均衡情况下获取真实ip的方法
    linux挂载硬盘
  • 原文地址:https://www.cnblogs.com/qingsong/p/3496488.html
Copyright © 2020-2023  润新知