Sign in to follow this  
Followers 0
MadBoy

Problem With Closing Gui But Not The Program Itself

4 posts in this topic

Heylo, need help once again :) The code below is supposed to start UDP service and wait for UDP signal.. when it receives it GUI BOX shows up with a button to press. WHen you either press it, or it timeouts or just exit with ESC it closes the GUI but the program is still running waiting for another udp signal. And now:

ExitLoop doesnt work at all in my case

GUISetState (@SW_HIDE, $GUISend) - just hides the GUI and if signal comes first then i have to wait for the Until time to pass so the next gui shows up. If more then one signal comes in i would like to receive another gui .. so even if application will get 3 udp signals i will have 3 GUI Windows open up.

Also Exit isn't good in that case because it kills the program.

Any help will be appreciated.

#include <GUIConstants.au3>

Dim $autor = "Me", $version = "0.1"
Dim $settings = @ScriptDir & "\UdpSend.ini"
Dim $udp_ip = IniRead($settings, "INFO", "udp_ip", "")
Dim $udp_port = IniRead($settings, "INFO", "udp_port", "")
Dim $udp_password = IniRead($settings, "INFO", "udp_password", "")
Dim $udp_command = IniRead($settings, "INFO", "udp_command", "")
Dim $position1 = 5, $position2 = 10, $nr_button1 = 30, $nr_button2 = 50
Dim $button[10], $label[10]
;==============Build GUI=============================================
$GUISend = GUICreate("UDP Reciver/Sender " & $autor & " - version " & $version, 600,200)
WinSetOnTop ( $GUISend, "", 1 )
$button[1] = GUICtrlCreateButton ("Send Me", $nr_button1, $nr_button2, 540, 120, $BS_DEFPUSHBUTTON)
$label[1]= GuiCtrlCreateInput("", $position1, $position2, 590, 20)


; Start The UDP Services
;==============================================
UDPStartup()
$socket_incoming = UDPBind("127.0.0.1", 4455)
If @error <> 0 Then Exit
$socket_outgoing = UDPOpen($udp_ip, $udp_port)
If @error <> 0 Then Exit

While 1
    $udp_receive_data = UDPRecv($socket_incoming, 2046)
    If $udp_receive_data <> "" Then
        GUISetState (@SW_SHOW, $GUISend)
       ;MsgBox(0, "UDP DATA", $udp_receive_data, 20)
        $udp_receive_data = StringStripWS ( $udp_receive_data, 8 )
        GUICtrlSetData( $Label[1], $udp_receive_data)
        $time = TimerInit(); start timer
        Do
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE 
                ExitLoop
               ;GUISetState (@SW_HIDE, $GUISend)
            Case $msg = $button[1]
                If $udp_password = 0 Then
                   ;$status = UDPSend($socket_outgoing, $udp_command & " " & $udp_receive_data)
                    MsgBox(1,1,1)
                    GUISetState (@SW_HIDE, $GUISend)
                Else
                   ;$status = UDPSend($socket_outgoing, $udp_command & " " & $udp_password & " " & $udp_receive_data)
                EndIf
            
               ;Exit
            EndSelect
        Until TimerDiff($time) > 8000; check timeout
    EndIf
    sleep(100)
WEnd

Func OnAutoItExit()
    UDPCloseSocket($socket_incoming)
    UDPCloseSocket($socket_outgoing)
    UDPShutdown()
EndFunc

My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites



I have not studied your code but from the description perhaps GUIDelete is the command you should use.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

GUIDelete, and put your GUI in a function so it can be called when necissary (sp).

My recommendations,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

I have not studied your code but from the description perhaps GUIDelete is the command you should use.

Tnx, That solves some but not all problems. I moved the Gui create into the loop so it will be recreated after it's deleted when i close it and when another UDP signal comes in. GUI Delete was working fine. I also added Exit Loop after GUI delete command. But now if i send multiple UDP lines into the script like 5 in 1 after another or so. Only one shows up at the time (that's okey i guess and can live with it) but after i close like 4 .. the last one doesn't want to be closed in any way.

#include <GUIConstants.au3>

Dim $autor = "Me", $version = "0.1"
Dim $settings = @ScriptDir & "\UdpSend.ini"
Dim $udp_ip = IniRead($settings, "INFO", "udp_ip", "")
Dim $udp_port = IniRead($settings, "INFO", "udp_port", "")
Dim $udp_password = IniRead($settings, "INFO", "udp_password", "")
Dim $udp_command = IniRead($settings, "INFO", "udp_command", "")
Dim $position1 = 5, $position2 = 10, $nr_button1 = 30, $nr_button2 = 50
Dim $button[10], $label[10]
;==============Build GUI=============================================



; Start The UDP Services
;==============================================
UDPStartup()
$socket_incoming = UDPBind("127.0.0.1", 65532)
If @error <> 0 Then Exit
$socket_outgoing = UDPOpen($udp_ip, $udp_port)
If @error <> 0 Then Exit

While 1
    $udp_receive_data = UDPRecv($socket_incoming, 2046)
    If $udp_receive_data <> "" Then
        $GUISend = GUICreate("UDP Reciver/Sender  " & $autor & " - version " & $version, 600,200)
        WinSetOnTop ( $GUISend, "", 1 )
        $button[1] = GUICtrlCreateButton ("SendMe", $nr_button1, $nr_button2, 540, 120, $BS_DEFPUSHBUTTON)
        $label[1]= GuiCtrlCreateInput("", $position1, $position2, 590, 20)
        GUISetState (@SW_SHOW, $GUISend)
        $udp_receive_data = StringStripWS ( $udp_receive_data, 8 )
        GUICtrlSetData( $Label[1], $udp_receive_data)
        $time = TimerInit(); start timer
        Do
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE 
                GUIDelete($GUISend)
                ExitLoop
            Case $msg = $button[1]
                If $udp_password = 0 Then
                    $status = UDPSend($socket_outgoing, $udp_command & " " & $udp_receive_data)
                Else
                    $status = UDPSend($socket_outgoing, $udp_command & " " & $udp_password & " " & $udp_receive_data)
                EndIf
                GUIDelete($GUISend)
                ExitLoop
            EndSelect
        Until TimerDiff($time) > 8000; check timeout
    EndIf
    sleep(100)
WEnd

Func OnAutoItExit()
    UDPCloseSocket($socket_incoming)
    UDPCloseSocket($socket_outgoing)
    UDPShutdown()
EndFunc

My little company: Evotec (PL version: Evotec)

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