搞了好一会儿,终于搞定!<br>利用剪贴板来传递memo中的数据。<br>======================<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils,Clipbrd,//Clipbrd是剪贴板的定义单元。加入。<br> Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> PfindWindowStruct =^ TFindWindowStruct;<br> TFindWindowStruct =record<br> caption: string;<br> classname:string;<br> windowsHandle: Thandle;<br> end;<br><br> TForm1 = class(TForm)<br> btn1: TButton;<br> mmo1: TMemo;<br> procedure btn1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br>implementation<br><br>{$R *.DFM}<br><br>//枚举所有的窗体的回调函数<br>function EnumwindowsProc(hWindow :hWnd;lParam:longInt):Bool ;<br>{$IFDEF WIN32} stdcall; {$ELSE};export; {$ENDIF}<br>VAR<br> lpBuffer
char;<br> windowcaptionFound:bool;<br> classNameFound:bool;<br>begin<br> GetMem(lpbuffer,255);<br> result:=true;<br> WindowCaptionFound:=false;<br> ClassNameFound:=false;<br> try<br> if GetWindowText(hWindow,lpBuffer,255)>0 then<br> if pos (pFindwindowstruct(lparam).caption,strPas(lpBuffer))>0 then<br> windowcaptionfound :=true;<br> if PfindWindowstruct(lParam).classname ='' then<br> Classnamefound:=true<br> else<br> if GetClassName (hwindow,lpBuffer,255) >0 then<br><br> if pos (pFindwindowstruct(lparam).caption,strPas(lpBuffer))>0 then<br> classnamefound:=true;<br> if (windowcaptionfound and classnamefound) then<br> begin<br> PfindWindowstruct(lparam).windowsHandle:=hwindow;<br> result:=false;<br> end;<br> finally<br> freemem (lpbuffer,sizeof(lpbuffer^));<br> end;<br>end;<br><br>//寻找窗体<br>function FindAwindow(caption:string;ClassName:string):Thandle;<br>var<br> WindowInfo: TfindWindowstruct;<br>begin<br> windowInfo.caption:=caption;<br> windowinfo.classname :=classname;<br> windowinfo.windowsHandle :=0;<br> EnumWindows (@EnumWindowsProc,LongInt(@windowInfo));<br> findAwindow := windowInfo.windowsHandle ;<br>end;<br><br>function EnumChildProc (Hwnd:integer;lParam:longint):boolean;<br>{$IFDEF WIN32} STDCALL;{$else}; export;{$endif}<br>var<br> MemoData :array[1..5000] of char; //可以根据需要再增大<br> clsName:array[0..5] of char;<br>begin<br> result:=false;<br> fillchar(MemoData,5000,#0);<br> GetClassName(Hwnd,@clsName,6);<br> if strcomp(clsname,'TMemo')=0 then<br> begin<br> //将MEMO中的内容全选<br> SendMessage(Hwnd, EM_SETSEL, 0, -1);<br> //拷贝内容,拷贝到剪贴板<br> SendMessage(Hwnd, WM_COPY, 0, 0);<br> Clipboard.GetTextBuf(@MemoData,5000);//将简帖板的内容给MemoData<br> form1.Mmo1.Lines.add(MemoData); //显示结果。<br> end;<br> Result:=true;<br>end;<br><br>procedure TForm1.btn1Click(Sender: TObject);<br>var<br> h :word;<br> cp
char;<br>begin<br> cp:='目标窗体的Caption';<br> h:=FindAWindow(cp,'');<br> enumchildwindows(h,@enumchildProc,0);<br>end;<br>end.<br><br>其他用途应该可以融会贯通。