本帖最后由 3mile 于 2011-8-1 20:27 编辑
借用4楼兄弟的另一个问题贴
http://www.autoitx.com/forum.php ... amp;fromuid=7639113
命令框输完命令"回车"即可
#include <ButtonConstants.au3>
#include <GUIButton.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIImageList.au3>
#include <GuiEdit.au3>
#include <WinAPIEx.au3>
HotKeySet("{F7}", "quit")
Func quit()
ProcessClose("cmd.exe")
Exit 0
EndFunc ;==>quit
Global $PT = 0
$HDL = Run(@ComSpec, "", @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED)
$GUIID = GUICreate("CMDshell", 600, 750)
$DISP = GUICtrlCreateEdit("", 10, 10, 580, 700, $Es_READONLY + $WS_VSCROLL + $WS_HSCROLL + $ES_OEMCONVERT)
GUICtrlSetLimit(-1, 1024 * 1024)
GUICtrlSetFont(-1, 9, 200, 0)
GUICtrlSetBkColor($DISP, 0x000000)
GUICtrlSetColor($DISP, 0x00FF00)
$CMDS = GUICtrlCreateEdit("commands...", 10, 720, 530, 20)
GUICtrlSetBkColor($CMDS, 0x000000)
GUICtrlSetColor($CMDS, 0xFFFFFF)
$BUTN = GUICtrlCreateButton("历史", 540, 720, 50, 20);,$BS_DEFPUSHBUTTON)
GUICtrlSetFont(-1, 8, 800, Default, "微软雅黑")
GUICtrlSetBkColor($BUTN, 0x000000)
GUICtrlSetColor($BUTN, 0x00FF00)
GUISetBkColor(0x000000)
$Dummy = GUICtrlCreateDummy()
GUISetState()
Local $Key[1][2] = [["{Enter}", $Dummy]]
GUISetAccelerators($Key)
_GUICtrlEdit_SetSel($CMDS, 0, -1)
While 1
$guimsg = GUIGetMsg()
Switch $guimsg
Case $GUI_EVENT_CLOSE
quit()
Case $BUTN
ShellExecute("out.txt")
;~ StdinWrite($HDL, _GUICtrlEdit_GetText($CMDS) & @CRLF)
;~ _GUICtrlEdit_SetSel($CMDS,0,-1)
Case $Dummy
Local $aResult = DllCall("user32.dll", "hwnd", "GetFocus")
If $aResult[0] = GUICtrlGetHandle($CMDS) Then
If _GUICtrlEdit_GetText($CMDS) = "cls" Then _GUICtrlEdit_SetText($DISP, "")
If _GUICtrlEdit_GetText($CMDS) = "exit" Then quit()
StdinWrite($HDL, _GUICtrlEdit_GetText($CMDS) & @CRLF)
_GUICtrlEdit_SetSel($CMDS, 0, -1)
EndIf
EndSwitch
$msg = StdoutRead($HDL)
If $msg <> "" Then
If _GUICtrlEdit_GetLineCount($DISP) > 500 Then
$hFile = FileOpen("out.txt", 1)
FileWrite($hFile, _GUICtrlEdit_GetText($DISP))
FileClose($hFile)
_GUICtrlEdit_SetText($DISP, "")
EndIf
_GUICtrlEdit_AppendText($DISP, $msg)
;~ $array = StringSplit($msg, @CRLF)
;~ _ArrayDisplay($array)
;~ For $i = 1 To $array[0]
;~ If $array[$i] = "" Then ContinueLoop
;~ _GUICtrlEdit_AppendText($DISP, _WinAPI_OemToChar($array[$i]) & @CRLF)
;~ Next
$msg = ""
EndIf
WEnd
|