- unit uTEditFill;
- interface
- uses Windows,SysUtils,Classes,Messages;
- const MaxSize = 10000;
- type
- TFormHandle = record
- Handle:THandle;
- Title:array [0..256]of Char;
- ClassName:array [0..256]of Char;
- end;
- TEditFill = class
- private
- FHandle:THandle;//目标窗口句柄
- FFormTitle:String;//目标窗口标题
- FData:TList;//写入Edit窗体内的数据
- FDestClassName:String;
- FCount:Integer;//计数器
- procedure SetFormTitle(const Value: string);
- procedure SetHandle(const Value: THandle);
- procedure SetData(const Value: TList);
- function GetParentHandle():THandle;//设置
- procedure SetDestClassName(const Value: String);
- procedure SetCount(const Value: Integer);
- public
- constructor Create();
- destructor Destroy();
- function FillEdit():boolean;//填充Edit窗体数据
- published
- property Data:TList read FData write SetData;
- property Count:Integer read FCount write SetCount;
- property Handle:THandle read FHandle write SetHandle;
- property DestClassName:String read FDestClassName write SetDestClassName;
- property FormTitle:string read FFormTitle write SetFormTitle;
- function EnumChildWndProc(AhWnd:LongInt;AlParam:lParam):boolean;stdcall;//尤其是这里其实这个 用法本身就不对
- end;
- implementation
- { TEditFill }
- constructor TEditFill.Create;
- begin
- FHandle:=0;
- FCount:=0;
- FFormTitle:='';
- FDestClassName:='';
- FData:=TList.Create;
- end;
- destructor TEditFill.Destroy;
- begin
- FHandle:=0;
- FFormTitle:='';
- FCount:=0;
- if FData.List <> nil then
- FData.Free;
- end;
- function TEditFill.EnumChildWndProc(AhWnd:LongInt;AlParam:lParam):boolean;stdcall;
- var
- ClassName,Text:PChar;
- begin
- if AhWnd <> 0 then
- GetClassName(AhWnd,@ClassName,256)
- else
- begin
- Raise Exception.Create('目标窗口句柄为空');
- exit;
- end;
- if SameText(String(ClassName),DestClassName) then
- begin
- SendMessage(aHwnd,WM_GETTEXT,0,Integer(Text));
- if Text = '' then
- begin
- if Count <= Data.Count then
- SendMessage(aHwnd,WM_SETTEXT,0,Integer(Data.Items[Count]));
- Count:=Count+1;
- end;
- end;
- Result:=True;
- end;
- function TEditFill.FillEdit: boolean;
- var
- aHandle:THandle;
- begin
- Result:=True;
- if FHandle <> 0 then
- begin
- aHandle:=FHandle;
- EnumChildWindows(aHandle,Self.MethodAddress('EnumChildWndProc'),0)
- end
- else
- Result:=False;
- end;
- function TEditFill.GetParentHandle: THandle;
- var
- aHandle:THandle;
- begin
- if FFormTitle = '' then
- begin
- raise Exception.Create('目标窗口标题不能为空');
- exit;
- end;
- if FindWindow(nil,Pchar(FFormTitle))<> 0 then
- aHandle:= FindWindow(nil,Pchar(FFormTitle));
- Result:=aHandle;
- end;
- procedure TEditFill.SetCount(const Value: Integer);
- begin
- FCount:=Value;
- end;
- procedure TEditFill.SetData(const Value: TList);
- begin
- if Value.List <> nil then
- FData.Assign(Value,laCopy,nil);
- end;
- procedure TEditFill.SetDestClassName(const Value: String);
- begin
- FDestClassName := Value;
- end;
- procedure TEditFill.SetFormTitle(const Value: string);
- begin
- FFormTitle:=Value;
- end;
- procedure TEditFill.SetHandle(const Value: THandle);
- begin
- if Value <> 0 then
- FHandle:=Value;
- end;
- end.
自己写的一个超级烂的类!警戒自己以后不要再写出如此糟糕的类!
最新推荐文章于 2024-01-13 13:03:36 发布