在向其他程序窗口中某一个控件里发送文本时,我做了这么一个函数,<br>但执行时连窗口都找不到,大家看看,想想办法。<br><br><br>function ShowChildWinID( WinCaption:string; CtrlClass:string ):boolean;<br>var<br> cnt: integer;<br><br> function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;<br> var<br> WindowCaption,WindowClass:array[0..254] of Char;<br> begin<br> GetClassName(Hwnd,WindowClass,255);<br> if Pos('CtrlClass',UpperCase(StrPas(WindowClass))) > 0 then<br> begin<br> Inc(cnt);<br> SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(IntToStr(cnt))));<br> //if cnt = ChildWinID then <br> //SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(s)));<br> //这里是为了向固定的ChildWinID显示S <br> end;<br> Result := True;<br> end;<br><br> function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;<br> var<br> WindowCaption:array[0..254] of Char;<br> WinCapStr:string;<br> begin<br> GetWindowText(Hwnd,WindowCaption,255);<br> if StrPas(WindowCaption)= WinCaption then<br> WinCapStr := StrPas(WindowCaption);<br> if WinCapStr = WinCaption then<br> begin<br> cnt := 0;<br> EnumChildWindows(Hwnd,@EnumChildProc,0);<br> Result := False;<br> Exit;<br> end;<br> Result := True;<br> end;<br><br>begin<br> Enumwindows(@EnumWindowsProc,0);<br>end;<br><br>///////////////////////////////////////////////////////////////////////////<br>调用方法<br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> ShowChildWinID('FormCustom','Edit');<br>end;