Jump to content
Sign in to follow this  
myspacee

Embedded DOS window

Recommended Posts

myspacee

Hello,

i made looping DOS script, that run few small batches.

Main script do things, create and stop processes, etc. Works well.

Now, my colleaugues and my boss, want a windows interface because we are in 2014,

DOS script are dead (!) and other rubbish like this...

I want to allow people that using this script to stop/start, monitor processes, make maintenance,

directly from GUI, and not from command line.

My question, is possibile to embed DOS window in a gui ?

So i can maintain script as is, and allow 'modern people' to push mouse button.

I know it's stupid task, but can be usefull in some cases.

thank you for any help,

m.

Share this post


Link to post
Share on other sites
FireFox

Hi,

Following >this example.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Run("cmd")

Local $hCmd = WinWait("[CLASS:ConsoleWindowClass]", "", 10)
If $hCmd = 0 Then Exit 1

Local $aOriPos = WinGetPos($hCmd)

Local $hGUI = GUICreate("MyGUI", $aOriPos[2], $aOriPos[3] + 200, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX))

GUICtrlCreateLabel("some buttons here", 10, 10)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_EXITSIZEMOVE, "WM_EXITSIZEMOVE")
GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")
GUISetState(@SW_SHOW, $hGUI)

Local $hOriParent = _WinAPI_SetParent($hCmd, $hGUI)

Local $iStyle = _WinAPI_GetWindowLong($hCmd, $GWL_STYLE)
_WinAPI_SetWindowLong($hCmd, $GWL_STYLE, BitXOR($iStyle, $WS_OVERLAPPEDWINDOW))

_WinAPI_SetWindowPos($hCmd, 0, 0, 200, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOACTIVATE, $SWP_NOZORDER, $SWP_NOSIZE))
_WinAPI_RedrawWindow($hCmd)

Local $iMsg = 0

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

;restore the cmd window
_WinAPI_SetParent($hCmd, $hOriParent)

_WinAPI_SetWindowLong($hCmd, $GWL_STYLE, $iStyle)
_WinAPI_SetWindowPos($hCmd, 0, $aOriPos[0], $aOriPos[1], $aOriPos[2], $aOriPos[3], BitOR($SWP_FRAMECHANGED, $SWP_NOACTIVATE, $SWP_NOZORDER))

GUIDelete($hGUI)

;when the cmd window is closed the gui is activated, so check if this one has been closed
Func WM_ACTIVATE($hWnd, $iMsg, $wParam, $lParam)
    If Number($wParam) = 1 And WinExists($hCmd) = 0 Then
        GUIDelete($hGUI)
        Exit
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

;otherwise the menu is not redrawn
Func WM_EXITSIZEMOVE($hWnd, $iMsg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_INVALIDATE)

    Return $GUI_RUNDEFMSG
EndFunc

;resize the cmd window according to the gui
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    Local $iWidth = BitAND($lParam, 0xFFFF)
    Local $iHeight = BitShift($lParam, 16)

    WinMove($hCmd, "", 0, 0, $iWidth, $iHeight)

    Return $GUI_RUNDEFMSG
EndFunc

You can also get the std in/out of the cmd, take a look at the StdinWrite,StdoutRead functions.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
myspacee

Hello,

thank you for reply, but, strangely, it works only first time i run it.

If i understand, CMD follows AI gui ?

try to understand why i can't replicate first run,

m.

Share this post


Link to post
Share on other sites
Belini

Another example posted by @ jscript.

#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

Local $vDos, $sline = ""

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("test", 446, 466, 283, 173)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 433, 385)
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
$Group1 = GUICtrlCreateGroup("Command", 8, 400, 433, 57)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 16, 424, 337, 21)
GUICtrlSetState(-1, $GUI_FOCUS)
$Button1 = GUICtrlCreateButton("Go Send", 360, 421, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;----> Create dummy keys for accelerators
$hENTER = GUICtrlCreateDummy()
Dim $AccelKeys[1][2] = [["{ENTER}", $hENTER]] ; Set accelerators
GUISetAccelerators($AccelKeys)
;<----

While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $Button1, $hENTER
                        $vDos = Run(@ComSpec & " /c " & GUICtrlRead($Input1), @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
                        While 1
                                $sline &= StdoutRead($vDos)
                                If @error Then ExitLoop
                        WEnd
                        GUICtrlSetData($Edit1, $sline & @CRLF)
                        GUICtrlSetData($Input1, "")
                        $sline = ""
        EndSwitch
WEnd
Edited by Belini

Share this post


Link to post
Share on other sites
myspacee

Hello,

solved one time run, givin to winwait a terget title:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Local $file = FileOpen("vivautoit.cmd", 10)

FileWrite($file, "@echo off" & @CRLF)
FileWrite($file, "title vivautoit" & @CRLF)
FileWrite($file, ":doyourjob" & @CRLF)
FileWrite($file, "cls" & @CRLF)
FileWrite($file, "time /T" & @CRLF)
FileWrite($file, "goto restart" & @CRLF)
FileWrite($file, ":restart" & @CRLF)
FileWrite($file, "goto doyourjob" & @CRLF)
FileClose($file)




Run('vivautoit.cmd')

Local $hCmd = WinWait("Amministratore:  vivautoit", "", 100)
If $hCmd = 0 Then Exit 1

Local $aOriPos = WinGetPos($hCmd)

Local $hGUI = GUICreate("MyGUI", $aOriPos[2], $aOriPos[3] + 200, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX))

GUICtrlCreateLabel("some buttons here", 10, 10)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_EXITSIZEMOVE, "WM_EXITSIZEMOVE")
GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")
GUISetState(@SW_SHOW, $hGUI)

Local $hOriParent = _WinAPI_SetParent($hCmd, $hGUI)

Local $iStyle = _WinAPI_GetWindowLong($hCmd, $GWL_STYLE)
_WinAPI_SetWindowLong($hCmd, $GWL_STYLE, BitXOR($iStyle, $WS_OVERLAPPEDWINDOW))

_WinAPI_SetWindowPos($hCmd, 0, 0, 200, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOACTIVATE, $SWP_NOZORDER, $SWP_NOSIZE))
_WinAPI_RedrawWindow($hCmd)

Local $iMsg = 0

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

;restore the cmd window
_WinAPI_SetParent($hCmd, $hOriParent)

_WinAPI_SetWindowLong($hCmd, $GWL_STYLE, $iStyle)
_WinAPI_SetWindowPos($hCmd, 0, $aOriPos[0], $aOriPos[1], $aOriPos[2], $aOriPos[3], BitOR($SWP_FRAMECHANGED, $SWP_NOACTIVATE, $SWP_NOZORDER))

GUIDelete($hGUI)

;when the cmd window is closed the gui is activated, so check if this one has been closed
Func WM_ACTIVATE($hWnd, $iMsg, $wParam, $lParam)
    If Number($wParam) = 1 And WinExists($hCmd) = 0 Then
        GUIDelete($hGUI)
        Exit
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

;otherwise the menu is not redrawn
Func WM_EXITSIZEMOVE($hWnd, $iMsg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_INVALIDATE)

    Return $GUI_RUNDEFMSG
EndFunc

;resize the cmd window according to the gui
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    Local $iWidth = BitAND($lParam, 0xFFFF)
    Local $iHeight = BitShift($lParam, 16)

    WinMove($hCmd, "", 0, 0, $iWidth, $iHeight)

    Return $GUI_RUNDEFMSG
EndFunc

Full title in my OS is  "Amministratore: vivautoit" (italian windows 7 x64)

It not possible to give to winwait function other params, to be sure that wait for my DOS batch?

Interesting layout for Belini, but can't run any command. How run given batch ?

Thank you for your time,

m.

Share this post


Link to post
Share on other sites
FireFox

It not possible to give to winwait function other params, to be sure that wait for my DOS batch?

Here you go :

...
Local $iPid = Run('vivautoit.cmd')

Local $hCmd = 0, $aWl = 0

While 1
    $aWl = WinList("Amministratore:  vivautoit")
    For $i = 1 To $aWl[0][0]
        If WinGetProcess($aWl[$i][1]) = $iPid Then
            $hCmd = $aWl[$i][1]
            ExitLoop 2
        EndIf
    Next
    Sleep(10)
WEnd

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×