自己写的一个超级烂的类!警戒自己以后不要再写出如此糟糕的类!
2008-11-07 09:49
706 查看
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.
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.
相关文章推荐
- 转载 对于技术术语专业化的思考(孟岩)(以后每次遇见一个术语,先查词典,不要被糟糕的中文译名所惑!)
- 第一篇 博客 记录一个自己写的性能超级差的方法 以后想办法找出原因
- 在一个人类生存的环境里,一个最先改变自己的人最聪明,后来改变自己的人还可以,而一个从来不改变自己的人是最糟糕的。
- 周鸿祎,高司令 2010-09-28 00:41 27469人阅读 评论(185) 收藏 举报 还是感到有必要将自己的一些想法快速记下来。 首先是对周鸿祎新员工演讲的看法。 就说实话这一点来说,周鸿祎比很多人强。所以我比较喜欢引用他的话,确实比较实在,不装逼。 至于一个公司招人的风格,是公司自己定的,别人也无权评价。有人说周是画大饼,忽悠员工卖命。废话,难道新员工讲话还有别的目的吗? 但我不认为周的选人思路在别的公司可以通行。原因是这样的:近十几年来,我们听到很多人有类似的说法,比如我们公司不要
- 一个51单片机比较综合的程序(包括了串口通信,io控制,字符串处理,中断处理),仅供自己以后参考
- “不要相信一个程序员在加班时间写出的代码”这是真的吗?
- 当你还不能写出自己满意的程序时,你就不要去睡觉。
- SuperTextView-从未如此惊艳!一个超级的TextView
- 关于XmlPullParser,记录下困扰自己两天的一个bug,以后多注意。
- 许多人都相信缘分,尤其是在爱情方面。事实上,茫茫人海,可以遇到一个跟自己毫无血缘关系的人,继而相知、相爱,最终结合在一起,这种缘分真的很奇妙。也许正因为此,爱情在我们的生命中才显得如此重要,而且永远是一个亘古不变的话题。但当两个人的缘分尽了,究竟又有几个可
- 一个开始吧。以后希望自己每天都能来写一下博客
- 今天给加上一个计数器,看到自己的Blog都生锈了啊!以后要好好维护!
- 写出一个你自己的MVC框架-基于对springMVC源码实现和理解(8):总结和对以后版本的展望
- 当你还不能写出自己满意的程序时,你就不要去睡觉。
- SuperTextView-从未如此惊艳!一个超级的TextView
- 使用多线程方法实现一个死锁程序,用来提醒自己不要犯这样的错误
- 不要随便扛起一个责任,尤其对越亲的人或者对自己期待越高的人,这样往往吃力不讨好
- 一个研究生毕业以后的人生规划(想抛砖引玉,谈谈自己看法,局限于理工科学生)
- 不要在意别人怎么说和怎么看,给自己一个机会
- 自己做的一个游戏 先不要看程序 想玩的自己复制粘贴运行 不然就没意思了