找回密码
 加入
搜索
查看: 40671|回复: 94

GUI能否内嵌CMD或TELNET?

 火... [复制链接]
发表于 2009-8-14 17:26:32 | 显示全部楼层 |阅读模式
本帖最后由 sunny617 于 2009-8-15 11:11 编辑

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

不知道能不能在GUI上内嵌,
如果可以的话,能在GUI上回显是个很不错的做法,方便查看...
一来不用去调用外部程序造成出错等问题.
请高人指点
发表于 2009-8-14 22:05:42 | 显示全部楼层
虽然这一切都是虚拟币
但是恰恰是对别人劳动的一种尊重和感激
希望大家都点给热心帮助人的坛友加加分
毕竟对这电脑敲代码也不是一件轻松的事
加加分也是对别人劳动价值的一种认可

评分

参与人数 2金钱 +20 贡献 +19 收起 理由
pusofalse + 5 + 10 敬佩
afan + 15 + 9 严重同感!都给你了

查看全部评分

 楼主| 发表于 2009-8-14 17:43:07 | 显示全部楼层
自己顶下....
发表于 2009-8-14 17:48:57 | 显示全部楼层
论坛搜索“回显”
 楼主| 发表于 2009-8-14 18:44:13 | 显示全部楼层
我想要的不只是回显出来简单
要像
$oIE = _IECreateEmbedded ()
$GUIActiveX = GUICtrlCreateObj($oIE,12, 38, 290, 164)
样..内嵌.加载telnet.exe  有个COM接口的在GUI上
有方法吗?
发表于 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[1][1]
; 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[0][0] - number of HWNDs
;                        $array[x][0] - title
;                        $array[x][1] - 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[1][1] = [[0]], $aWin, $hTimer = TimerInit()
    
    While 1
        
    ; Get list of windows
        $aWin = WinList($sTitle)
        
    ; Searches thru all windows
        For $i = 1 To $aWin[0][0]
            
        ; Found a window owned by the given PID
            If $iPid = WinGetProcess($aWin[$i][1]) Then
                
            ; Option 0 or 1 used
                If $iOption = 1 OR ($iOption = 0 And $aWin[$i][0] <> "") Then
                    Return $aWin[$i][1]
                
            ; Option 2 is used
                ElseIf $iOption = 2 Then
                    ReDim $aReturn[UBound($aReturn) + 1][2]
                    $aReturn[0][0] += 1
                    $aReturn[$aReturn[0][0]][0] = $aWin[$i][0]
                    $aReturn[$aReturn[0][0]][1] = $aWin[$i][1]
                EndIf
            EndIf
        Next
        
    ; If option 2 is used and there was matches then the list is returned
        If $iOption = 2 And $aReturn[0][0] > 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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 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][1]) = $iPID Then Return $aWinList[$i][1]
    Next
    
    Return 0
EndFunc
Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +20 贡献 +15 收起 理由
破帽遮颜 + 20 + 15 恶意灌水,扣分警告!

查看全部评分

发表于 2009-8-14 20:04:38 | 显示全部楼层

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

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

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


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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 2金钱 +22 贡献 +15 收起 理由
sunny617 + 2 最后2分给了你...呵呵
破帽遮颜 + 20 + 15 送点给你!你也别那么小气嘛

查看全部评分

发表于 2009-8-14 21:40:54 | 显示全部楼层
打劫啊~~~~~~~~~~~~

评分

参与人数 1金钱 +4 收起 理由
lynfr8 + 4 大家老兄弟了,打个6折啦

查看全部评分

发表于 2009-8-14 21:57:39 | 显示全部楼层
送了那么多,还钱!

评分

参与人数 1金钱 +6 收起 理由
lynfr8 + 6 我今天的分都加光了

查看全部评分

发表于 2009-8-14 22:01:30 | 显示全部楼层
打折啊~~~~~~~~~~~~

评分

参与人数 1金钱 +4 收起 理由
lynfr8 + 4 也是熟面孔了,打6折

查看全部评分

发表于 2009-8-14 22:02:18 | 显示全部楼层
今天没钱还人情了
看到热心帮助人的坛友我每天的奉献和金钱都帮他们加光了
个人觉得别人付出了心思和时间来为提问的解答
很多人连谢谢都没有
也没有帮他们加加分加加奉献什么的
我就狠狠加啊加
呵呵
 楼主| 发表于 2009-8-15 11:05:29 | 显示全部楼层
打劫啊~~~~~~~~~~~~
破帽遮颜 发表于 2009-8-14 21:40

===========================================================


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

感谢,,,抢回来好好研究下....
 楼主| 发表于 2009-8-15 11:06:07 | 显示全部楼层
唉...回个贴正好10个大洋...哈哈

 楼主| 发表于 2009-8-15 11:07:45 | 显示全部楼层
11# lynfr8
--------------------------------------------

加来加去你的金钱上K了

评分

参与人数 1金钱 +2 收起 理由
lynfr8 + 2 和谐社会允许一部分人先富起来,别仇富哦, ...

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-24 23:59 , Processed in 0.078367 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表