Sign in to follow this  
Followers 0
Eviltim

Help Array/gui Problem

10 posts in this topic

Hi! its been a while since i posted.

Pic of what im doing: It some sort of command line console im working on.

Posted Image

Im trying to execute a dos command in a hidden window and output the text to the gui.

i finally got it working but with some small problems.

a number is displayed at the top that should not be there(seems to be a line count of the array)

Posted Image

Heres the code.

Func _IpConfig()
        Local $s_OutDos
        $s_OutDos = _TempFile("%TEMP%", "tst_", ".dos")
        $sCommand = "Ipconfig"
        _RunDOS($sCommand & ' > ' & $s_OutDos);~ <Process.au3> ---
        _FileReadToArray($s_OutDos, $b)
        _FileReadToArray($s_TempFile, $a)
        _ArrayPush($a,$b)                   ;~ <Array.au3> ---
        _FileWriteFromArray($s_TempFile, $a)
        $OldLines = FileRead($s_TempFile)
        $output= $OldLines & @CRLF  
        $CountLines = _FileCountLines($s_TempFile)
        If $CountLines = 18 Then
            _FileWriteToLine($s_TempFile, 1, "", 1)
            Else
        EndIf
        GUICtrlSetData( $log, $output, 1)
EndFunc

And here is the rest of the code so it makes a little more sense maybe.

#include <GUIConstants.au3>
#include <File.au3>
#Include <String.au3>
#include <Process.au3>
#include <Array.au3>


Dim $output, $OldLines, $clear, $temp, $LastInput, $i = 0, $EnableLog = 0, $a, $b

Opt("GUIOnEventMode", 1)

HotKeySet("+{Esc}", "ToggleDown")
HotKeySet("{Up}", "PrevInput")
HotKeySet("{Down}", "NextInput")

$gui = GUICreate("Console", @DesktopWidth, 325, 0, 0, $WS_POPUP + $WS_SYSMENU + $WS_MINIMIZEBOX, $WS_EX_TOPMOST)
GUISetBkColor(0x022A2A)

;~  Main Label ---
$s_TempFile = _TempFile()
FileWriteLine($s_TempFile, _StringRepeat(@CRLF ,17));~ Start Text From Bottom <String.au3> --- 
_FileReadToArray($s_TempFile, $clear)               ;~ <File.au3> ---
$con = FileReadLine($s_TempFile, 1)
$log = GUICtrlCreateLabel($con & @CRLF, 40, 35, 728, 235, -1, $WS_EX_STATICEDGE )
GUICtrlSetColor(-1, 0xF5F5F5)
GUICtrlSetBkColor(-1,0x024D42)

GUICtrlCreatePic("TL_Corner.gif", 15, 10, 25, 25)
GUICtrlCreateLabel("", 20, 35, 20, 235);~ Left Border ---
GUICtrlSetBkColor(-1,0x02222A)
GUICtrlCreatePic("BL_Corner.gif", 15, 270, 25, 25)
GUICtrlCreateLabel("", 40, 270, 728, 20);~ Bottom Border ---
GUICtrlSetBkColor(-1,0x02222A)
GUICtrlCreatePic("TR_Corner.gif", 768, 10, 25, 25)
GUICtrlCreateLabel("Console v0.2", 40, 15, 728, 20);~ Top Border ---
GUICtrlSetFont(-1, 12)
GUICtrlSetColor(-1, 0xF5F5F5)
GUICtrlSetBkColor(-1,0x02222A)
GUICtrlCreatePic("BR_Corner.gif", 768, 270, 25, 25)
GUICtrlCreateLabel("", 768, 35, 20, 235);~ Right Border ---
GUICtrlSetBkColor(-1,0x02222A)
;~  End ---

$Input = GUICtrlCreateInput("", 41, 300, 728, 20)
GUICtrlSetColor(-1, 0xF5F5F5)
GUICtrlSetBkColor(-1,0x02222A)
GUICtrlSetState( $Input, $GUI_FOCUS)

$button = GuiCtrlCreateButton("Send", 900, 900, 70, 20);~ Hides the Button ---
GUICtrlSetOnEvent(-1, "Input")
GUICtrlSetState( $button, $GUI_DEFBUTTON)

GUICtrlCreateLabel("", 0, 323, @DesktopWidth, 2)
GUICtrlSetBkColor(-1, 0xFF0404)

GUICtrlSetState( $button, $GUI_DISABLE)
GUICtrlSetState( $Input, $GUI_DISABLE)

;~ WinSetTrans("Console", "", 175)
 
Func ToggleDown()
    GUICtrlSetState( $button, $GUI_ENABLE)
    GUICtrlSetState( $Input, $GUI_ENABLE)
    GUICtrlSetState( $Input, $GUI_FOCUS)
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 150, "long", 0x00040004);slide-in from top
    HotKeySet("+{Esc}", "ToggleUp")
    GUISetState()
EndFunc
Func ToggleUp()
    GUICtrlSetState( $button, $GUI_DISABLE)
    GUICtrlSetState( $Input, $GUI_DISABLE)
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 150, "long", 0x00050008);slide-out to top
    HotKeySet("+{Esc}", "ToggleDown")
EndFunc

Func _IpConfig()
        Local $s_OutDos
        $s_OutDos = _TempFile("%TEMP%", "tst_", ".dos")
        $sCommand = "Ipconfig"
        _RunDOS($sCommand & ' > ' & $s_OutDos);~ <Process.au3> ---
        _FileReadToArray($s_OutDos, $b)
        _FileReadToArray($s_TempFile, $a)
        _ArrayPush($a,$b)                   ;~ <Array.au3> ---
        _FileWriteFromArray($s_TempFile, $a)
        $OldLines = FileRead($s_TempFile)
        $output= $OldLines & @CRLF  
        $CountLines = _FileCountLines($s_TempFile)
        If $CountLines = 18 Then
            _FileWriteToLine($s_TempFile, 1, "", 1)
            Else
        EndIf
        GUICtrlSetData( $log, $output, 1)
EndFunc

Func Input()
        $F = GUICtrlRead($Input)
        If $F = "" Then
            Else
            FileWriteLine($s_TempFile, $F)
            If $EnableLog = 0 Then
                Else
                _FileWriteLog(@ScriptDir & "\console.log", $F)
            EndIf
            $OldLines = FileRead($s_TempFile)       ;
            $output= $OldLines & @CRLF              ;
            $CountLines = _FileCountLines($s_TempFile);
            If $CountLines = 18 Then                ;~ Scroll Text From Bottom to Top Effect ---
                _FileWriteToLine($s_TempFile, 1, "", 1);
                Else                                ;
            EndIf                                   ;
            GUICtrlSetData( $log, $output, 1)
            GUICtrlSetData($Input, "")
            Call($F)
            $i = 0
        EndIf
EndFunc

Func StartLog()
    $EnableLog = 1
EndFunc
Func StopLog()
    $EnableLog = 0
EndFunc

Func PrevInput()
    Select
;~  Case $LastInput = ""
    Case $i = 17
    Case Else
        $i = $i + 1
        _FileReadToArray($s_TempFile, $LastInput)
        GUICtrlSetData($Input, $LastInput[18 - $i])
    EndSelect
EndFunc

Func NextInput()
    Select
;~  Case $LastInput = ""
    Case $i = 0
    Case Else
        $i = $i - 1
        _FileReadToArray($s_TempFile, $LastInput)       
        GUICtrlSetData($Input, $LastInput[18 - $i])
    EndSelect
EndFunc

Func Close()
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 1000, "long", 0x00090000);fade-out
    Exit
EndFunc  ;==>Close
    
Func Clear()
    $F= GUICtrlRead($Input)
    GUICtrlSetData( $log, "")
    GUICtrlSetData($Input, "")
    _FileWriteFromArray($s_TempFile, $clear,1)
EndFunc

While 1
    Sleep(10); Idle around
WEnd;--Loop

Im also trying to find a way to call the function to use any dos command[like _Dos(Ipconfig)]

Not sure how to do that. :mellow:

Any Tips, Improvements, or anything would be much appriciated.(spelling :) )

P.S. I Think i failed at posting images properly, and forgive me if i dont make any sense at all!!

-Thanks

Share this post


Link to post
Share on other sites



Im trying to execute a dos command in a hidden window and output the text to the gui.

i finally got it working but with some small problems.

a number is displayed at the top that should not be there(seems to be a line count of the array)

Any Tips, Improvements, or anything would be much appriciated.(spelling :) )

P.S. I Think i failed at posting images properly, and forgive me if i dont make any sense at all!!

-Thanks

Consider the code below:

Case $msg = $traceitem
        If $ClientWeb Then
                        
            HotKeySet("{Esc}", "abortTrace")

            GUICtrlSetData($Edit1, "Tracing Route To: " & $ClientWeb & " - press Escape to quit" & @crlf, 1)
            Sleep(1000)
            $trinfo = Run(@ComSpec & " /c tracert -h 30 -w " & $timeOut & " " & $ClientWeb, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)    
            While 1
        ;
            $line = StdoutRead($trinfo, -1)
                If @error = -1  Then 
                    ExitLoop
Else
                GUICtrlSetData($Edit1, $line, 1)
                EndIf
            Wend
        EndIf

The area you are interested in would be:

$trinfo = Run(@ComSpec & " /c tracert -h 30 -w " & $timeOut & " " & $ClientWeb, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)    
            While 1
            
            $line = StdoutRead($trinfo, -1)
                If @error = -1  Then 
                    ExitLoop
Else
                GUICtrlSetData($Edit1, $line, 1)
                EndIf
            Wend

The run command is running the traceroute in a hidden dos window, and the StdoutRead in the while loop is displaying the output in a GUI control (in this case a read only edit control)

Here is a link to the post containing a network utility that I wrote. The ideas you are looking for are in it.

http://www.autoitscript.com/forum/index.ph...network+utility

HTH

Share this post


Link to post
Share on other sites

thanks billmez, this is definetly what im looking for. ill post again when if i run into any problems.

(probably tommorow)

Still wonder why im getting that number at the beggining. becuase in other functions

(NextInput, PrevInput) i get the number 18 when i try to recall the very last input typed.

(first line of the array i think)

Share this post


Link to post
Share on other sites

thanks billmez, this is definetly what im looking for. ill post again when if i run into any problems.

(probably tommorow)

Still wonder why im getting that number at the beggining. becuase in other functions

(NextInput, PrevInput) i get the number 18 when i try to recall the very last input typed.

(first line of the array i think)

From the help file:

Success: Returns the exit code of the command

so

_RunDOS($sCommand & ' > ' & $s_OutDos);~ <Process.au3> ---

appears to also echo the exit code of the command into the $s_OutDos file.

Try:

$ReturnVar = _RunDOS($sCommand & ' > ' & $s_OutDos);~ <Process.au3> ---

and see if it does not echo the exit code since you have assigned a variable to hold it.

I believe the functions in the link I sent previously will do what you want. If you need the output in a file, you can assign each output line to a variable using &= and the write it to a file after the process has finished.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I usually preffer displaying the data while the process is running, like:

Local $ipconfig = Run(@ComSpec & " /c " & 'ipconfig /all', "", @SW_HIDE, 2)
while 1
   $data = StdoutRead($ipconfig)
   If @error = -1 Then ExitLoop
   _output_function($data);;display $data (define _output_function yourself)
wend

#)

Edit: Looks very interesting!!! Hope to see more of this soon.

Edited by nfwu

Share this post


Link to post
Share on other sites

I usually preffer displaying the data while the process is running, like:

That is exactly what this block does in the above snippet, send each line to an edit control:

$trinfo = Run(@ComSpec & " /c tracert -h 30 -w " & $timeOut & " " & $ClientWeb, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)    
            While 1
       ;
            $line = StdoutRead($trinfo, -1)
                If @error = -1  Then 
                    ExitLoop
Else
                GUICtrlSetData($Edit1, $line, 1)
                EndIf

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

works great! almost completely done the whole thing over.

heres the new function

Func Dos($s_command)
        $ipinfo = Run(@ComSpec & " /c "& $s_command , @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
        While 1
            $line = StdoutRead($ipinfo, -1) & @CRLF
            If @error = -1 Then ExitLoop
            GUICtrlSetData($log, $line, 1)
        Wend
EndFunc

and the rest...

#include <GUIConstants.au3>
#include <File.au3>
#Include <String.au3>
#include <Constants.au3>

Dim $output, $OldLines, $clear, $i = -1, $EnableLog = 0

Opt("GUIOnEventMode", 1)

HotKeySet("+{Esc}", "ToggleDown")
HotKeySet("{Up}", "PrevInput")
HotKeySet("{Down}", "NextInput")

$gui = GUICreate("Console", @DesktopWidth, 325, 0, 0, $WS_POPUP + $WS_SYSMENU + $WS_MINIMIZEBOX, $WS_EX_TOPMOST)
GUISetBkColor(0x022A2A)
;~  Main Label ---
$s_TempFile = _TempFile()
FileWriteLine($s_TempFile, _StringRepeat(@CRLF ,17));~ Start Text From Bottom <String.au3> --- 
_FileReadToArray($s_TempFile, $clear)               ;~ <File.au3> ---
$con = FileRead($s_TempFile)
$log = GUICtrlCreateEdit($con & @CRLF, 40, 35, 728, 235, $ES_READONLY + $WS_VSCROLL, $WS_EX_CLIENTEDGE)
GUICtrlSetColor(-1, 0xF5F5F5)
GUICtrlSetBkColor(-1,0x024D42)
GUICtrlSetFont ($log,9, 400, 0, "Lucida Console")

GUICtrlCreatePic("TL_Corner.gif", 15, 10, 25, 25)
GUICtrlCreateLabel("", 20, 35, 20, 235);~ Left Border ---
GUICtrlSetBkColor(-1,0x02222A)
GUICtrlCreatePic("BL_Corner.gif", 15, 270, 25, 25)
GUICtrlCreateLabel("", 40, 270, 728, 20);~ Bottom Border ---
GUICtrlSetBkColor(-1,0x02222A)
GUICtrlCreatePic("TR_Corner.gif", 768, 10, 25, 25)
GUICtrlCreateLabel("Console v0.3", 40, 15, 728, 20);~ Top Border ---
GUICtrlSetFont(-1, 12)
GUICtrlSetColor(-1, 0xF5F5F5)
GUICtrlSetBkColor(-1,0x02222A)
GUICtrlCreatePic("BR_Corner.gif", 768, 270, 25, 25)
GUICtrlCreateLabel("", 768, 35, 20, 235);~ Right Border ---
GUICtrlSetBkColor(-1,0x02222A)
;~  End ---

$Input = GUICtrlCreateInput("", 41, 300, 728, 20)
GUICtrlSetColor(-1, 0xF5F5F5)
GUICtrlSetBkColor(-1,0x02222A)
GUICtrlSetState( $Input, $GUI_FOCUS)

$button = GuiCtrlCreateButton("Send", 900, 900, 70, 20);~ Hides the Button ---
GUICtrlSetOnEvent(-1, "Input")
GUICtrlSetState( $button, $GUI_DEFBUTTON)

GUICtrlCreateLabel("Res Test", @DesktopWidth - 60, 300, 50, 20)
GUICtrlSetColor(-1, 0xF5F5F5)
GUICtrlSetBkColor(-1, 0xFF0404)

GUICtrlCreateLabel("", 0, 323, @DesktopWidth, 2)
GUICtrlSetBkColor(-1, 0xFF0404)

GUICtrlSetState( $button, $GUI_DISABLE)
GUICtrlSetState( $Input, $GUI_DISABLE)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 0, "long", 0x00080000);fade-in
Sleep(1000)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 0, "long", 0x00050008);slide-out to top
WinSetTrans("Console", "", 175)
Func ToggleDown()
    GUICtrlSetState( $button, $GUI_ENABLE)
    GUICtrlSetState( $Input, $GUI_ENABLE)
    GUICtrlSetState( $Input, $GUI_FOCUS)
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 0, "long", 0x00040004);slide-in from top
    HotKeySet("+{Esc}", "ToggleUp")
    GUISetState()
EndFunc
Func ToggleUp()
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 0, "long", 0x00050008);slide-out to top
    GUICtrlSetState( $button, $GUI_DISABLE)
    GUICtrlSetState( $Input, $GUI_DISABLE)
    HotKeySet("+{Esc}", "ToggleDown")
EndFunc

Func Dos($s_command)
        $ipinfo = Run(@ComSpec & " /c "& $s_command , @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
        While 1
            $line = StdoutRead($ipinfo, -1) & @CRLF
            If @error = -1 Then ExitLoop
            GUICtrlSetData($log, $line, 1)
        Wend
EndFunc
;~  Reference ---
Func _Trace()
        Dim $timeOut = 3000
        $trinfo = Run(@ComSpec & " /c tracert -h 30 -w " & $timeOut & " " & "http://www.google.com", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)   
        While 1
        $line = StdoutRead($trinfo, -1)
        If @error = -1  Then
            ExitLoop
            Else
            GUICtrlSetData($log, $line, 1)
        EndIf
        Wend
EndFunc
    
Func _PingIt($strHost)
    Dim $timeOut = 3000
    GUICtrlSetData($log, "Testing Connection " & $strHost & @crlf, 1)
    Sleep(1000)
For $i = 1 to 3
$Preturn = Ping ($strHost, $timeOut)
Sleep(1000)
    If $Preturn Then
        $Pdisplay = "Host: " & $strHost & " Found: " & $Preturn & " ms Round Trip"
    Else
        $Pdisplay = "Host: " & $strHost & " REQUEST TIME OUT"
    EndIf
GUICtrlSetData($log, $Pdisplay & @crlf, 1)
Next    
GUICtrlSetData($log, @crlf, 1)
EndFunc 
;~  End ---

Func Input()
        $F = GUICtrlRead($Input)
        If $F = "" Then
            Else
            FileWriteLine($s_TempFile, $F)
            GUICtrlSetData($log, @CRLF, 1);~ Insures every new line starts at the bottom ---
            If $EnableLog = 0 Then
                Else
                _FileWriteLog(@ScriptDir & "\console.log", $F)
            EndIf
            $output = $F
            GUICtrlSetData($log, $output, 1)
            GUICtrlSetData($Input, "")
            $Fn = StringSplit($F, "(")
            $count = ($Fn[0])
            Select
            Case $count = 3
                Call($Fn[1], $Fn[2], $Fn[3])
            Case $count = 2
                Call($Fn[1], $Fn[2])
            Case $count = 1
                Call($Fn[1])
            EndSelect
            $i = -1
        EndIf
EndFunc

Func StartLog()
    $EnableLog = 1
EndFunc
Func StopLog()
    $EnableLog = 0
EndFunc

Func PrevInput()
    Select
    Case $i = 20
    Case Else
        $i = $i + 1
        $count = _FileCountLines($s_TempFile)
        If FileReadLine($s_TempFile, $count - $i) = "" Then
            $i = $i - 1
            Else
            GUICtrlSetData($Input, FileReadLine($s_TempFile, $count - $i))
        EndIf
    EndSelect
EndFunc

Func NextInput()
    Select
    Case $i = 0
    Case Else
        $i = $i - 1
        $count = _FileCountLines($s_TempFile)
        If FileReadLine($s_TempFile, $count - $i) = "" Then
            $i = $i + 1
            Else
            GUICtrlSetData($Input, FileReadLine($s_TempFile, $count - $i))
        EndIf
    EndSelect
EndFunc

Func Close()
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 1000, "long", 0x00090000);fade-out
    Exit
EndFunc  ;==>Close
    
Func Clear()
    GUICtrlSetData( $log, $con)
    GUICtrlSetData($Input, "")
    _FileWriteFromArray($s_TempFile, $clear,1)
EndFunc

While 1
    Sleep(10); Idle around
WEnd;--Loop

i also figured out where the numbers are coming from, was reading about StringSplit() and saw this

"the first element ($array[0]) contains the number of strings returned"

found that out after i redid erverything ^^

Thank you for the help, billmez.

Edit1: Fixed the PrevInput, NextInput to do nothing when it reads a blank line.

Edited by Eviltim

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Just 2 questions:

q1

Is there away to resize the gui when the screen resokution changes?

i know id have to resize some of the labels at the same time..

q2

Is it possible to round out the corners of labels?(im using 4 different gifs now)

i know it can be done on the window itself.

Edited by Eviltim

Share this post


Link to post
Share on other sites

Just 2 questions:

q1

Is there away to resize the gui when the screen resokution changes?

i know id have to resize some of the labels at the same time..

q2

Is it possible to round out the corners of labels? i know it can be done on the window itself.

Question 1: Look at using @DeskTopWidth - or + some coords and @DeskTopHeight - or + some coords for the width and height.

Question 2: I have no idea what your talking about.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Question 1: Look at using @DeskTopWidth - or + some coords and @DeskTopHeight - or + some coords for the width and height.

Question 2: I have no idea what your talking about.

ill see about question 1

question 2, im using rounded edge gifs on each corner.

it can be done on the gui window itself.

Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
    Dim $pos, $ret, $ret2
    $pos = WinGetPos($h_win)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3, "long", $i_y3)
    If $ret[0] Then
        $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
        If $ret2[0] Then
            Return 1
        Else
            Return 0
        EndIf
    Else
        Return 0
    EndIf
EndFunc  ;==>_GuiRoundCorners

but can it be done from within?

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  
Followers 0