zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    阻止事件的默认行为,例如click <a>后的跳转~
    阻止事件冒泡
    IE67不兼容display:inline-block,CSS hack解决
    IE678不兼容CSS3 user-select:none(不可复制功能),需要JS解决
    JS数组常用方法总结
    json 只能用 for-in 遍历
    用实例的方式去理解storm的并发度
    OpenLDAP 搭建入门
    kafka api的基本使用
    kafka基本介绍
  • 原文地址:https://www.cnblogs.com/qingsong/p/3496488.html
Copyright © 2011-2022 走看看