sunny617 发表于 2009-8-14 17:26:32

GUI能否内嵌CMD或TELNET?

本帖最后由 sunny617 于 2009-8-15 11:11 编辑

学会了内嵌IE 就是没有搞明白怎么内嵌CMD或TELNET

不知道能不能在GUI上内嵌,
如果可以的话,能在GUI上回显是个很不错的做法,方便查看...
一来不用去调用外部程序造成出错等问题.
请高人指点
:face (29):

lynfr8 发表于 2009-8-14 22:05:42

虽然这一切都是虚拟币
但是恰恰是对别人劳动的一种尊重和感激
希望大家都点给热心帮助人的坛友加加分
毕竟对这电脑敲代码也不是一件轻松的事
加加分也是对别人劳动价值的一种认可

sunny617 发表于 2009-8-14 17:43:07

自己顶下....

lynfr8 发表于 2009-8-14 17:48:57

论坛搜索“回显”

sunny617 发表于 2009-8-14 18:44:13

我想要的不只是回显出来简单
要像
$oIE = _IECreateEmbedded ()
$GUIActiveX = GUICtrlCreateObj($oIE,12, 38, 290, 164)
样..内嵌.加载telnet.exe有个COM接口的在GUI上
有方法吗?

lynfr8 发表于 2009-8-14 19:43:38

本帖最后由 lynfr8 于 2009-8-14 20:05 编辑

嵌入程序到GUI倒是可以做到
不过也不是很好用,不如IE内嵌那么完美
主要就是拖动有残影

效果图:
#include <GUIConstants.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Global $WS_POPUP, $WS_BORDER
$mainWindow = GUICreate("Embed Cmd", 500, 500, 10, 10)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState (@SW_SHOW)
GUIRegisterMsg(0xF, "WM_PAINT")
; create a borderless window that is a child to the main window
$embedWindow = GUICREATE("", 477, 165, 15, 320, $WS_POPUP, -1, $mainWindow)
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $embedWindow, "hwnd", $mainWindow)
; launch the command prompt (black on white, without the operating system message)
$pid = run("cmd.exe /T:F0 /k")
ProcessWait ($pid)
; get the handle of the cmd window as i cannot be certain that there will be only one instance of the cmd running with the same window title or class
$cmdHandle = _ProcessGetHWnd($pid, 2)
$hWndChild = $cmdHandle
; make the command prompt window a child to the earlier created borderless child window
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $embedWindow)
; resize the command prompt window so that its bolder and title bar are outside the borderless child window
;giving the appearance of a borderless command prompt
WinMove($hWndChild, '', -4, -30, 485, 206)
WinSetState($hWndChild, '', @SW_SHOW)
WinSetState($embedWindow, '', @SW_SHOW)
; inifinite event loop
While 1
; sleep for 100 milliseconds (to not hog the cpu)
    sleep(100)
   
; end of event loop   
WEnd

Func CLOSEClicked()   
; take care of things to do when exiting
    Winkill($hWndChild)
    Exit
EndFunc

Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    Sleep(100)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc;==>WM_PAINT

;===============================================================================
;
; Function Name:    _ProcessGetHWnd
; Description:      Returns the HWND(s) owned by the specified process (PID only !).
;
; Parameter(s):   $iPid      - the owner-PID.
;                  $iOption    - Optional : return/search methods :
;                        0 - returns the HWND for the first non-titleless window.
;                        1 - returns the HWND for the first found window (default).
;                        2 - returns all HWNDs for all matches.
;
;                   $sTitle      - Optional : the title to match (see notes).
;                  $iTimeout    - Optional : timeout in msec (see notes)
;
; Return Value(s):On Success - returns the HWND (see below for method 2).
;                        $array - number of HWNDs
;                        $array - title
;                        $array - HWND
;
;                   On Failure    - returns 0 and sets @error to 1.
;
; Note(s):            When a title is specified it will then only return the HWND to the titles
;                  matching that specific string. If no title is specified it will return as
;                  described by the option used.
;
;                  When using a timeout it's possible to use WinWaitDelay (Opt) to specify how
;                  often it should wait before attempting another time to get the HWND.
;
;
; Author(s):      Helge
;
;===============================================================================
Func _ProcessGetHWnd($iPid, $iOption = 1, $sTitle = "", $iTimeout = 2000)
    Local $aReturn = [], $aWin, $hTimer = TimerInit()
   
    While 1
      
    ; Get list of windows
      $aWin = WinList($sTitle)
      
    ; Searches thru all windows
      For $i = 1 To $aWin
            
      ; Found a window owned by the given PID
            If $iPid = WinGetProcess($aWin[$i]) Then
               
            ; Option 0 or 1 used
                If $iOption = 1 OR ($iOption = 0 And $aWin[$i] <> "") Then
                  Return $aWin[$i]
               
            ; Option 2 is used
                ElseIf $iOption = 2 Then
                  ReDim $aReturn
                  $aReturn += 1
                  $aReturn[$aReturn] = $aWin[$i]
                  $aReturn[$aReturn] = $aWin[$i]
                EndIf
            EndIf
      Next
      
    ; If option 2 is used and there was matches then the list is returned
      If $iOption = 2 And $aReturn > 0 Then Return $aReturn
      
    ; If timed out then give up
      If TimerDiff($hTimer) > $iTimeout Then ExitLoop
      
    ; Waits before new attempt
      Sleep(Opt("WinWaitDelay"))
    WEnd
   
   
; No matches
    SetError(1)
    Return 0
EndFunc;==>_ProcessGetHWnd

lynfr8 发表于 2009-8-14 19:46:29

再给一个官网例子

本帖最后由 lynfr8 于 2009-8-14 19:54 编辑


#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Global $Init_Dir = "C:\"
$Main_GUI = GUICreate("Embed Command Line Prompt", 550, 300, 10, 10)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
GUIRegisterMsg(0xF, "WM_PAINT")
$iCmd_PID = Run(@ComSpec & " /k CD " & $Init_Dir, "", @SW_HIDE)
ProcessWait($iCmd_PID)
$Embed_hWnd = _GetHWndByPID($iCmd_PID)
WinMove($Embed_hWnd, "", -2, -23, 549, 342)
WinSetState($Embed_hWnd, "", @SW_SHOWMINIMIZED)
GUISetState(@SW_SHOW, $Main_GUI)
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $Embed_hWnd, "hwnd", $Main_GUI)

While 1
    Sleep(100)
    If WinActive($Main_GUI) Then WinActivate($Embed_hWnd)
WEnd
Func Quit()
    ProcessClose($iCmd_PID)
    Exit
EndFunc
Func _GetHWndByPID($iPID)
    Local $aWinList = WinList()
   
    For $i = 1 To UBound($aWinList)-1
      If WinGetProcess($aWinList[$i]) = $iPID Then Return $aWinList[$i]
    Next
   
    Return 0
EndFunc
Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc

lynfr8 发表于 2009-8-14 20:04:38

2009.8.16已经修正无法运行第二次问题

本帖最后由 lynfr8 于 2009-8-16 15:32 编辑

明码标价10大洋,公开公正交易。


更正声明:
已经修正无法第二次正常使用的问题
主要是中文字符引起的字符计算错误导致无法正确获取输入命令
在这里向之前付钱下载的朋友说声抱歉

破帽遮颜 发表于 2009-8-14 21:40:54

打劫啊~~~~~~~~~~~~

破帽遮颜 发表于 2009-8-14 21:57:39

送了那么多,还钱!

afan 发表于 2009-8-14 22:01:30

打折啊~~~~~~~~~~~~

lynfr8 发表于 2009-8-14 22:02:18

今天没钱还人情了
看到热心帮助人的坛友我每天的奉献和金钱都帮他们加光了
个人觉得别人付出了心思和时间来为提问的解答
很多人连谢谢都没有
也没有帮他们加加分加加奉献什么的
我就狠狠加啊加
呵呵

sunny617 发表于 2009-8-15 11:05:29

打劫啊~~~~~~~~~~~~
破帽遮颜 发表于 2009-8-14 21:40 http://www.autoitx.com/images/common/back.gif
===========================================================


果然是打劫.........

感谢,,,抢回来好好研究下....

sunny617 发表于 2009-8-15 11:06:07

唉...回个贴正好10个大洋...哈哈

:face (7):

sunny617 发表于 2009-8-15 11:07:45

11# lynfr8
--------------------------------------------

加来加去你的金钱上K了:face (31):
页: [1] 2 3 4 5 6 7
查看完整版本: GUI能否内嵌CMD或TELNET?