如果用FindWindowEx不能找到合适的Handle,那么可以用EnumChildWindows枚举所有窗体上控件的Handle,例:<br>var<br> Step: Integer = 0;<br><br>function EnumChildProc(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;<br>begin<br> Result:=True;<br><br> Inc(Step);<br> case Step of<br> 3: SetWindowText(hwnd,'要赋的值'); //比如窗体上第三个为文本框T1<br> 5: SendString(hwnd,'要赋的值'); //比如窗体上第五个为文本框T2,有些程序没办法用SetWindowText改变文本框的值,那么可以用模拟按键的方法给其赋值,具体代码在下面<br> end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> Step:=0;<br> EnumChildWindows(找到的窗体句柄,@EnumChildProc,0);<br>end;<br><br>procedure SendShift(hwnd: HWND; Down: Boolean);<br>var<br> vKey,ScanCode,wParam: Word;<br> lParam: LongInt;<br>begin<br> vKey:=$10;<br><br> ScanCode:=MapVirtualKey(vKey,0);<br> wParam:=vKey or ScanCode shl 8;<br> lParam:=LongInt(ScanCode) shl 16 or 1;<br><br> if not Down then<br> lParam:=lParam or LongInt($C0000000);<br> SendMessage(hwnd,WM_KEYDOWN,wParam,lParam);<br>end;<br><br>procedure SendCtrl(hwnd: HWND; Down: Boolean);<br>var<br> vKey,ScanCode,wParam: Word;<br> lParam: LongInt;<br>begin<br> vKey:= $11;<br><br> ScanCode:=MapVirtualKey(vKey,0);<br> wParam:=vKey or ScanCode shl 8;<br> lParam:=LongInt(ScanCode) shl 16 or 1;<br><br> if not Down then<br> lParam:=lParam or LongInt($C0000000);<br> SendMessage(hwnd,WM_KEYDOWN,wParam,lParam);<br>end;<br><br>procedure SendKey(hwnd: HWND; Key: Char);<br>var<br> vKey,ScanCode,wParam: Word;<br> lParam,ConvKey: LongInt;<br> Shift,Ctrl: Boolean;<br>begin<br> ConvKey:=OemKeyScan(Ord(Key));<br> Shift:=(ConvKey and $00020000)<>0;<br> Ctrl:=(ConvKey and $00040000)<>0;<br> ScanCode:=ConvKey and $000000FF or $FF00;<br> vKey:=Ord(Key);<br> wParam:=vKey;<br> lParam:=LongInt(ScanCode) shl 16 or 1;<br><br> if Shift then<br> SendShift(hwnd,True);<br> if Ctrl then<br> SendCtrl(hwnd,True);<br><br> SendMessage(hwnd,WM_KEYDOWN,wParam,lParam);<br> SendMessage(hwnd,WM_CHAR,wParam,lParam);<br><br> lParam:=lParam or LongInt($C0000000);<br> SendMessage(hwnd,WM_KEYUP,wParam,lParam);<br><br> if Shift then<br> SendShift(hwnd,False);<br> if Ctrl then<br> SendCtrl(hwnd,False);<br>end;<br><br>procedure SendString(hwnd: HWND; Str: String);<br>var<br> i: Integer;<br>begin<br> for i:=1 to Length(Str) do<br> SendKey(hwnd,Str);<br>end;<br><br><br>相信以上几步后满足你的要求是没问题的了