MoriceGrene Posted May 26 Posted May 26 Hi i have this code expandcollapse popup#include <GUIConstants.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Sound.au3> Opt("GUIOnEventMode", 1) Global Const $SC_DRAGMOVE = 0xF012 Global $sIniPath = @ScriptDir & "\Config.ini" Global $idLabel Global $sAlertFile Global $btnExit Global $AllertNotify Global $bExit = False main() While Not $bExit GUIGetMsg() ; <-- fondamentale per gestire eventi GUI in GUIOnEventMode=1 Sleep(100) WEnd Func main() ; === Leggi percorso MT5 dal file ini === Local $mt5ExchangePath = IniRead($sIniPath, "MT5_path_exchange", "MT5Pth", "") If $mt5ExchangePath = "" Then MsgBox($MB_ICONERROR, "Errore", "Percorso MT5 mancante nella sezione [MT5_path_exchange] del Config.ini") Exit EndIf $sAlertFile = $mt5ExchangePath & "\NoSoundAlerts.txt" ; === Ottieni handle finestra MT5 via CLASS === Local $hMT5 = WinGetHandle("[CLASS:MetaQuotes::MetaTrader::5.00]") If @error Or $hMT5 = 0 Then MsgBox($MB_ICONERROR, "Errore", "Impossibile trovare la finestra di MT5.") Exit EndIf ; === Layout finestra GUI === Local $btnHeight = 30 Local $guiWidth = 583 Local $aRes = WinGetClientSize("[CLASS:Progman]") Local $posX = $aRes[0] - $guiWidth - 240 Local $posY = $aRes[1] - $btnHeight - 65 ; === Crea GUI figlia della finestra MT5 === $AllertNotify = GUICreate("Alert Viewer", $guiWidth, $btnHeight, $posX, $posY, BitOR($WS_POPUP, $WS_BORDER), -1, $hMT5) ; === Label dinamica === $idLabel = GUICtrlCreateLabel("In attesa di segnali...", 5, 5, $guiWidth - 70, $btnHeight, $SS_LEFTNOWORDWRAP) GUICtrlSetFont($idLabel, 9, 700, 0, "Segoe UI") ; === Bottone Exit === $btnExit = GUICtrlCreateButton("Exit", $guiWidth - 60, 5, 55, 20) ; === Mostra GUI === WinSetOnTop($AllertNotify, "", 1) GUISetState() ; === Eventi GUI === GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetOnEvent($btnExit, "OnExit") ; === Avvia monitoraggio file === AdlibRegister("AttachToMT5", 500) EndFunc Func AttachToMT5() Static $sLastMessage = "" If FileExists($sAlertFile) Then Local $sContent = FileRead($sAlertFile) If Not @error And StringStripWS($sContent, 3) <> "" Then If $sContent <> $sLastMessage Then GUICtrlSetData($idLabel, $sContent) $sLastMessage = $sContent ; Suono quando arriva nuova alert Beep(500, 1000) ; oppure usa SoundPlay per suoni personalizzati ; SoundPlay(@WindowsDir & "\Media\notify.wav", 1) EndIf ; Svuota il file dopo lettura Local $hFile = FileOpen($sAlertFile, 2) If $hFile <> -1 Then FileWrite($hFile, "") FileClose($hFile) EndIf EndIf EndIf EndFunc Func OnExit() ; Ferma il timer Adlib AdlibUnRegister("AttachToMT5") ; Chiudi la GUI GUIDelete($AllertNotify) ; Imposta flag per uscita dal ciclo $bExit = True EndFunc why if i push button close it not close app ? ramaning in loop ?
argumentum Posted May 26 Posted May 26 1 hour ago, MoriceGrene said: GUIGetMsg() ; <-- fondamentale per gestire eventi GUI in GUIOnEventMode=1 "essential to handle GUI events in GUIOnEventMode=1". Is not needed when using GUIOnEventMode. 1 hour ago, MoriceGrene said: Func OnExit() ; Ferma il timer Adlib AdlibUnRegister("AttachToMT5") ; Chiudi la GUI GUIDelete($AllertNotify) ; Imposta flag per uscita dal ciclo $bExit = True EndFunc you can just: Func OnExit() ;~ ; Stop Adlib timer ;~ AdlibUnRegister("AttachToMT5") ;~ ; Close GUI ;~ GUIDelete($AllertNotify) ;~ ; Set flag to exit loop ;~ $bExit = True Exit EndFunc ..welcome to the forum MoriceGrene 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now