Jump to content

Recommended Posts

Posted

Hello AutoIt :),

As the title is saying I have below a simple code.

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

$Form1 = GUICreate("Wait Exist", 340, 64, -1, -1)
$Button1 = GUICtrlCreateButton("Wait Exist", 16, 16, 75, 25)
$Button2 = GUICtrlCreateButton("Message", 156, 16, 75, 25)
GUISetState(@SW_SHOW, $Form1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            For $i = 0 To 3
                MsgBox(0,'',$i)
                While Not FileExists(@DesktopDir & '\ExampleFile.txt')
                WEnd
            Next

        Case $Button2
            MsgBox(0, '', '')

    EndSwitch
WEnd

Here I must wait for a file to exist while using the menu at the same time. The problem is that I can't use an Adlibregister cause I use a for and it must wait for the file to exist before continue. EXAMPLE

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

$Form1 = GUICreate("Wait Exist", 340, 64, -1, -1)
$Button1 = GUICtrlCreateButton("Wait Exist", 16, 16, 75, 25)
$Button2 = GUICtrlCreateButton("Message", 156, 16, 75, 25)
GUISetState(@SW_SHOW, $Form1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            For $i = 0 To 3
                MsgBox(0,'',$i)
                AdlibRegister('_Wait',1000)
            Next

        Case $Button2
            MsgBox(0, '', '')

    EndSwitch
WEnd

Func _Wait()
    If FileExists(@DesktopDir & '\ExampleFile.txt') Then
    EndIf
EndFunc

 

How can I do that?

Thank you! :) 

Posted (edited)
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Wait Exist", 340, 64, -1, -1)
$Button1 = GUICtrlCreateButton("Wait Exist", 16, 16, 75, 25)
$Button2 = GUICtrlCreateButton("Message", 156, 16, 75, 25)
GUISetState(@SW_SHOW, $Form1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            For $i = 0 To 3
                MsgBox(0,'',$i)
                While Not FileExists(@DesktopDir & '\ExampleFile.txt')
                    $nMsg = GUIGetMsg()
                    If $nMsg = $GUI_EVENT_CLOSE Then Exit
                    If $nMsg = $Button2 Then FuncButton2()
                WEnd
            Next

        Case $Button2
            FuncButton2()

    EndSwitch
WEnd

Func FuncButton2()
    MsgBox(0, 'Button2', '')
EndFunc

 

Edited by Zedna
Posted

Another way (especially if you got a large and complex GUI) :

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

$Form1 = GUICreate("Wait Exist", 340, 64, -1, -1)
$Button1 = GUICtrlCreateButton("Wait Exist", 16, 16, 75, 25)
$Button2 = GUICtrlCreateButton("Message", 156, 16, 75, 25)
GUISetState(@SW_SHOW, $Form1)

Local $bWaiting = False

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit
    Case $Button1
      $bWaiting = True
      GUICtrlSetState ($Button1, $GUI_DISABLE)
    Case $Button2
      FuncButton2()
  EndSwitch
  If $bWaiting And FileExists ("your path goes here") Then
    ;do stuff here
    GUICtrlSetState ($Button1, $GUI_ENABLE)
    $bWaiting = False
  EndIf
WEnd

Func FuncButton2()
  MsgBox(0, 'Button2', '')
EndFunc   ;==>FuncButton2

 

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
×
×
  • Create New...