Delphi窗口随机类名

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
procedure CreateParams(var Parames:TCreateParams);override;
Function Randstring():string;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

Function tform1.Randstring():string;
var
i,t,n:Integer;
c,s:string;
begin
repeat
randomize();
n:=Random(16);
until (n>=6) and (n<=16) ;
for i:=0 to n do
begin
if i=0 then t:=Random(25)+10 else t:=Random(35);
case t of
0 :c:='0';
1 :c:='1';
2 :c:='2';
3 :c:='3';
4 :c:='4';
5 :c:='5';
6 :c:='6';
7 :c:='7';
8 :c:='8';
9 :c:='9';
10:c:='a';
11:c:='b';
12:c:='c';
13:c:='d';
14:c:='e';
15:c:='f';
16:c:='g';
17:c:='h';
18:c:='i';
19:c:='j';
20:c:='k';
21:c:='l';
22:c:='m';
23:c:='n';
24:c:='o';
25:c:='p';
26:c:='q';
27:c:='r';
28:c:='s';
29:c:='t';
30:c:='u';
31:c:='v';
32:c:='w';
33:c:='x';
34:c:='y';
35:c:='z';
end;
s:=s+c;
end;
Result:=s;

end;

procedure TForm1.CreateParams(var Parames: TCreateParams);
var
t:string;
i:Integer;
begin
inherited CreateParams(Parames);
t:= Randstring() ;
for i:=1 to Length(t) do
begin
Parames.WinClassName:=t;
end;

end;

procedure TForm1.Button1Click(Sender: TObject);

var
Name:array[0..MAXBYTE] of char;
begin
GetClassName(Handle,Name,255);
ShowMessage(Name);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
form1.Caption:=Randstring();
end;

end.