function GetLocalTextInfo(var ReturnEditHandle:Integer):String;<br>var AHandle, BHandle: Integer;<br> R:Boolean;<br> mbuffer: array[0..255] of Char;<br> ss:string; <br>{$WRITEABLECONST ON}//这是用于静态变量somedata增加的开关,防止同类型控件只能找到第一个,你单步执行调整变量i的值就可以找到你需要的控件<br> function GetComponentHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br> var s,sssss:string;<br> i,j:integer;<br> buffer: array[0..255] of Char; <br> const<br> somedata: Integer = 0;<br> begin<br> j:=0;i:=2;<br> if DebugState then sssss:='TEDIT'<br> else sssss:='.EDIT.';<br> Result := True;<br> //得到目标窗口的控件<br> j:=GetClassName(hwnd, buffer, 256);<br> //找到目标窗口的TButton类目标控件<br> s:=StrPas(Buffer);<br> if Pos(sssss,uppercase(s))>0 then<br> begin<br> if DebugState then begin<br> inc(somedata);<br> if somedata=i then begin<br> somedata:=0;<br> Result:=False; //终止循环<br> end;<br> end else begin<br> PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)<br> Result:=False; //终止循环<br> end;<br> end;<br> end; <br>{$WRITEABLECONST OFF}<br>begin<br> //取句柄<br> AHandle := FindWindow(nil, 'MasterLabelPrint'); //就是窗口的Caption<br> //AHandle := FindWindow(nil, 'G/BOX组装防错系统'); //就是窗口的Caption<br> if AHandle<>0 then<br> begin<br> //在这里循环取到想要的句柄为止<br> R:=EnumChildWindows(AHandle, @GetComponentHandle, Integer(@BHandle));<br> if not R then begin<br> ReturnEditHandle:=BHandle;<br> SendMessage(BHandle,WM_GETTEXT,254,Integer(@mbuffer));<br> //GetWindowText(BHandle, mbuffer, 100);<br> ss:=StrPas(mBuffer);<br> Result:=ss;<br> end;<br> //此时,BHandle就是你要的句柄<br> //PostMessage(BHandle, BM_Click, 0, 0); //向这个按钮发一个点击消息<br> end;<br>end;