下面的方法可以输入字符,但是有新的问题,怎样将要输入字符的窗口置前,<br>窗口置前也有办法,用<br>procedure SwitchToThisWindow(hWnd: HWND; bRestore: Boolean); stdcall;<br>implementation<br>procedure SwitchToThisWindow; external 'user32.dll' name 'SwitchToThisWindow';<br>就可以了,但是还有新问题,怎样通过程序文件名得到窗口Handle,这个问题我真在问<br><br><br>const<br> MAGIC_CONSOLE_TOGGLE=57359;<br>var<br> StartupInfo: _STARTUPINFOA;<br> ProcessInfo: _PROCESS_INFORMATION;<br> hInput: Cardinal;<br> Han: THandle;<br> ExitCode: DWORD;<br> ddd: Integer;<br> i: Integer;<br> dwOldMode: DWORD;<br> dwNewMode: DWORD;<br> hOut: THandle;<br> hConsole: THandle;<br>begin<br> FillChar(StartupInfo,SizeOf(StartupInfo),#0);<br> StartupInfo.cb:=SizeOf(StartupInfo);<br> StartupInfo.dwFlags:=STARTF_USESHOWWINDOW;<br> StartupInfo.wShowWindow:=SW_SHOW;<br> AllocConsole;<br> hInput:=GetStdHandle(STD_INPUT_HANDLE);<br> StartupInfo.hStdOutput:=GetStdHandle(STD_OUTPUT_HANDLE);<br> StartupInfo.hStdInput:=hInput;<br> CreateProcess(nil,'c:/command.com',nil,nil,True,0,nil,nil,StartupInfo,ProcessInfo);<br> Sleep(1000);<br> keybd_event($31,MapVirtualKey($31,0),0,0);<br> keybd_event($31,MapVirtualKey($31,0),KEYEVENTF_KEYUP,0);<br> keybd_event($32,MapVirtualKey($32,0),0,0);<br> keybd_event($32,MapVirtualKey($32,0),KEYEVENTF_KEYUP,0);<br> keybd_event(13,MapVirtualKey(13,0),0,0);<br> keybd_event(13,MapVirtualKey(13,0),KEYEVENTF_KEYUP,0);<br> Sleep(5000);<br> WaitForSingleObject(ProcessInfo.hProcess,INFINITE);<br> FreeConsole;<br> Han:=OpenProcess(PROCESS_TERMINATE,True,ProcessInfo.dwProcessId);<br> GetExitCodeProcess(Han,ExitCode);<br> TerminateProcess(Han,ExitCode);