Jump to content

Flickering in fileread script


Recommended Posts

I just cant seem to get rid of the flickering everytime my script reads from a file and presents it...Have read a couple of forum answers, but it seem it only works with "time" and stuff...Here is my code:

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Global $file97, $file98, $line99, $thefile, $varNet1, $MSG, $test, $GOOEY, $edit, $var, $GOOEY, $WS_EX_COMPOSITED, $timer, $test

Global $szIPADDRESS = @IPAddress1

Opt("MustDeclareVars", 1)

$GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")", 350, 400)

$file97 = @HomeDrive & "\test.log"

GUISetState()

While 1

$MSG = GUIGetMsg()

Select

Case $MSG = $GUI_EVENT_CLOSE

ExitLoop

Case $MSG = $test

$varNet1 = Run(@ComSpec & ' /c ' & 'netstat -p TCP >c:\test.log', @SystemDir, @SW_HIDE)

$file98 = FileOpen($file97, 0)

$line99 = FileRead($file98)

FileClose($file98)

$edit = GUICtrlCreateLabel($line99, 10, 10, 380, 180)

Sleep(1000)

EndSelect

WEnd

It's not THAT much of an issue, but it would be nice if i could get rid of it...I'm not sure if it has something to do with the refresh rate or something something like that

Edited by Robin
Link to comment
Share on other sites

Look at the last option in Run. As I recall, you don't need to write it to a file, rather read the output into a variable.

Not sure how your script works, but you might be able to read the file before you make the window visible.

Link to comment
Share on other sites

Look at the last option in Run. As I recall, you don't need to write it to a file, rather read the output into a variable.

Not sure how your script works, but you might be able to read the file before you make the window visible.

What this script does, is getting information fron test.log every 1 sec, and then read it.

you maybe got me a sample code? (my script IS complete)

Edited by Robin
Link to comment
Share on other sites

No, but try $STDOUT_CHILD as the last option and use StdoutRead.

StdoutRead has samle code.

Ive tried it but doesnt seem to work...it must read continuesly without a messagebox, but as a label...

Like i say, my code works 100%...its only the f'n flicker...lol

but let me fiddle with the code a bit as im still a newbie with THIS command

Edited by Robin
Link to comment
Share on other sites

  • Moderators

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

Global $h_gui, $i_edit, $h_edit
Global $s_stdout, $s_old_stdout, $i_pid, $i_timer, $i_sec = 1
Global $s_ip = @IPAddress1

$h_gui = GUICreate("My Server (IP: " & $s_ip & ")", 400, 400)
$i_edit = GUICtrlCreateEdit("", 10, 10, 380, 180)
GUISetState()
$h_edit = GUICtrlGetHandle($i_edit)
$i_timer = TimerInit()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    
    If TimerDiff($i_timer) / 1000 >= $i_sec Then
        $i_pid = Run(@ComSpec & " /c netstat -p TCP", @SystemDir, @SW_HIDE, 6)
        While 1
            $s_stdout &= StdoutRead($i_pid)
            If @error Then ExitLoop
        WEnd
        If $s_stdout And $s_stdout <> $s_old_stdout Then
            WinSetState($h_edit, "", @SW_LOCK)
            GUICtrlSetData($i_edit, "")
            GUICtrlSetData($i_edit, $s_stdout)
            WinSetState($h_edit, "", @SW_UNLOCK)
            $s_old_stdout = $s_stdout
        EndIf
        $s_stdout = ""
        $i_timer = TimerInit()
    EndIf
WEnd

Edit:

BTW - You were creating a control every second as well without ever deleting the former control (just putting controls 1 on top of the other)... that's very bad.

Edited by SmOke_N

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.

Link to comment
Share on other sites

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

Global $h_gui, $i_edit, $h_edit
Global $s_stdout, $s_old_stdout, $i_pid, $i_timer, $i_sec = 1
Global $s_ip = @IPAddress1

$h_gui = GUICreate("My Server (IP: " & $s_ip & ")", 400, 400)
$i_edit = GUICtrlCreateLabel("", 10, 10, 380, 180)
GUISetState()
$h_edit = GUICtrlGetHandle($i_edit)
$i_timer = TimerInit()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    
    If TimerDiff($i_timer) / 1000 >= $i_sec Then
        $i_pid = Run(@ComSpec & " /c netstat -p TCP", @SystemDir, @SW_HIDE, 6)
        While 1
            $s_stdout &= StdoutRead($i_pid)
            If @error Then ExitLoop
        WEnd
        If $s_stdout And $s_stdout <> $s_old_stdout Then
            WinSetState($h_edit, "", @SW_LOCK)
            GUICtrlSetData($i_edit, "")
            GUICtrlSetData($i_edit, $s_stdout)
            WinSetState($h_edit, "", @SW_UNLOCK)
            $s_old_stdout = $s_stdout
        EndIf
        $s_stdout = ""
        $i_timer = TimerInit()
    EndIf
WEnd

Edit:

BTW - You were creating a control every second as well without ever deleting the former control (just putting controls 1 on top of the other)... that's very bad.

'SmOke_N', youre a BUFF!!...Works 100%...Thx a lot

Out of curiosity...Where does the "trick" with the flickering come in in the code you gave me?

thx a bunch hey ^_^

Link to comment
Share on other sites

'SmOke_N', youre a BUFF!!...Works 100%...Thx a lot

Out of curiosity...Where does the "trick" with the flickering come in in the code you gave me?

thx a bunch hey ^_^

oops sorry....didnt read your response there
Link to comment
Share on other sites

  • Moderators

'SmOke_N', youre a BUFF!!...Works 100%...Thx a lot

Out of curiosity...Where does the "trick" with the flickering come in in the code you gave me?

thx a bunch hey ^_^

There's no trick. Your major flicker was described in my edit.

Checking if the control even needs to be updated isn't a bad thing either.

Also note my last edit, I have the "Label" as an edit control... you're missing half of the data with just a label with no way to read it.

I would suggest comparing my code to yours, and you'd see the major differences.

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.

Link to comment
Share on other sites

I would suggest comparing my code to yours, and you'd see the major differences.

Busy doing it at the moment and yeah...huge diff. With al honesty, and it might sound major stupid, but i NEVER knew you had to "flush"( so to speak ) controls...lol

Ooo ok...see what you mean...because its inside a "loop" (first time i use it THIS way.

Edited by Robin
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...