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.

 

转载于:https://www.cnblogs.com/qingsong/p/3496488.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值