Jump to content

Recommended Posts

Posted (edited)

Hi i have create a script , in this script i never used checkbox  but apear in gui a checkbox o_O (In addition to the fact that Flick)

why ? image.png.00532b853076156d162c879b947f067f.png

if i go over and try to click in square  appear a botton like this

image.png.cec44bc41822915d29ed2f15ce1688c5.png

but after refreash disappear

#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Opt("GUIOnEventMode", 1) ; Event Mode ON

Global Const $SC_DRAGMOVE = 0xF012
Global $sIniPath = @ScriptDir & "\Config.ini"
Global $sToolboxFile

Global $aTradeRows[0]
Global $AllertNotify
Global $sIniPath      = @ScriptDir & "\Config.ini"
Global $sCommandsPath = IniRead($sIniPath, "MT5_path_exchange", "MT5Pth", @ScriptDir)
Global $gGroupDynamic = 0

main()

Func main()
    Local $mt5ExchangePath = IniRead($sIniPath, "MT5_path_exchange", "MT5Pth", "")
    If $mt5ExchangePath = "" Then
        MsgBox(16, "Errore", "Percorso MT5 mancante nel Config.ini")
        Exit
    EndIf

    $sToolboxFile = $mt5ExchangePath & "\toolbox.txt"

    Local $hMT5 = WinGetHandle("[CLASS:MetaQuotes::MetaTrader::5.00]")
    If @error Or $hMT5 = 0 Then
        MsgBox(16, "Errore", "Finestra MT5 non trovata.")
        Exit
    EndIf

    ; === GUI ===
    Local $guiWidth = 685, $guiHeight = 30
    Local $aRes = WinGetPos("[CLASS:Progman]")
    Local $posX = $aRes[0] + $aRes[2] - $guiWidth - 5
    Local $posY = $aRes[1] + 43

    $AllertNotify = GUICreate("Trades", $guiWidth, $guiHeight, $posX, $posY, _
        BitOR($WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), -1, $hMT5)

    GUISetOnEvent($GUI_EVENT_CLOSE, "_DoNothing")
    WinSetOnTop($AllertNotify, "", 1)
    GUISetState(@SW_SHOW)

    LoadTradesFromFile()
    AdlibRegister("ReloadTrades", 3000)
EndFunc

Func _DoNothing()
    ; Vuoto
EndFunc

Func ReloadTrades()
    If $gGroupDynamic Then GUICtrlDelete($gGroupDynamic) ; cancella il contenitore

    $gGroupDynamic = GUICtrlCreateGroup("", 0, 0, 685, 30) ; contenitore invisibile
    GUICtrlSetState($gGroupDynamic, $GUI_HIDE)

    ReDim $aTradeRows[0]
    LoadTradesFromFile()

    GUICtrlSetState($gGroupDynamic, $GUI_SHOW)
EndFunc

Func LoadTradesFromFile()
    If Not FileExists($sToolboxFile) Then Return 0

    Local $hFile = FileOpen($sToolboxFile, 0)
    If $hFile = -1 Then Return 0

    Local $x = 10
    Local $y = 5
    Local $tradeCount = 0

    While 1
        Local $line = FileReadLine($hFile)
        If @error Then ExitLoop

        Local $parts = StringSplit($line, ",")
        If $parts[0] <> 3 Then ContinueLoop

        Local $symbol = $parts[1]
        Local $ticket = $parts[2]
        Local $net = $parts[3]
        Local $color = (Number($net) < 0) ? 0xFF0000 : 0x009900

        Local $text = StringFormat("%s | %s", $symbol, $net)
        Local $textSize = StringLen($text) * 7

        ; Associa label e button al gruppo dinamico!
Local $label = GUICtrlCreateLabel($text, $x, $y + 3, $textSize, 22, 0, $gGroupDynamic)

        GUICtrlSetFont($label, 9, 800)
        GUICtrlSetColor($label, $color)
        _ArrayAdd($aTradeRows, $label)

        Local $btn = GUICtrlCreateButton($ticket, $x + $textSize, $y - 1, 60, 24, $gGroupDynamic)
        GUICtrlSetData($btn, $ticket)
        GUICtrlSetOnEvent($btn, "_OnCloseTrade")
        _ArrayAdd($aTradeRows, $btn)

        $x += $textSize + 70
        $tradeCount += 1
    WEnd

    ; Bottone "Chiudi tutto" fuori dal ciclo, associato anch'esso al gruppo
    Local $closeAllBtnX = 685 - 35
    Local $btnCloseAll = GUICtrlCreateButton("X", $closeAllBtnX + 10, 5, 20, 20, $gGroupDynamic)
    GUICtrlSetFont($btnCloseAll, 10, 800)
    GUICtrlSetOnEvent($btnCloseAll, "_OnCloseAllTrade")

    FileClose($hFile)
    Return $tradeCount
EndFunc

Func _OnCloseTrade()
    Local $ticket = GUICtrlRead(@GUI_CtrlId)
    Local $cmd = "CLOSE," & $ticket
    Local $cmdFile = $sCommandsPath & "\commands.txt"

    Local $hFile = FileOpen($cmdFile, 2 + 8)
    If $hFile <> -1 Then
        FileWriteLine($hFile, $cmd)
        FileClose($hFile)
        MsgBox(64, "Comando inviato", "Chiudi trade #" & $ticket)
    Else
        MsgBox(16, "Errore", "Impossibile scrivere nel file di comando.")
    EndIf
EndFunc
Func _OnCloseAllTrade()
    MsgBox(64, "Chiudi Tutto", "Chiudi tutti i trade.")
    ; In futuro: scrivi il comando CLOSE_ALL nel file
EndFunc


While 1
    Sleep(100)
WEnd

this is my code

Edited by Melba23
Removed "bug" reference from title
Posted

As you can see, I can't test the script, so I'm just speculating
At first glance, there are some irregularities here
Local $label = GUICtrlCreateLabel($text, $x, $y + 3, $textSize, 22, 0, $gGroupDynamic)
Local $btn = GUICtrlCreateButton($ticket, $x + $textSize, $y - 1, 60, 24, $gGroupDynamic)
Local $btnCloseAll = GUICtrlCreateButton("X", $closeAllBtnX + 10, 5, 20, 20, $gGroupDynamic)

you use as style or as exStyle to $gGroupDynamic = GUICtrlCreateGroup("", 0, 0, 685, 30) ; contenitore invisibile

which doesn't seem right to me.

I know that I know nothing

Posted

sorry you can create a file config.ini inside of root of  script  ,

[BottoniRossi]
B1=0.01
B2=0.10
B3=0.50
B4=1
B5=2

[BottoniVerdi]
B1=2
B2=1
B3=0.50
B4=0.10
B5=0.01

[Generale]
DisplayTesto=INFO

[MT5_Title]
MT5T=Toolbox

[MT5_path_exchange]
MT5Pth=C:\Users\pct\AppData\Roaming\MetaQuotes\Terminal\CAE0DBC4018C08FC6206EE952D921887\MQL5\Files

and  after  i read i file toolbox.txt   inside i have this text   XUSTEC, 845152555,-12   

usally i have many and  change  frequently less 1 second , but  do that another program you can simulate  with this  probably

#include <File.au3>
#include <Date.au3>

; === CONFIGURAZIONE ===
Global $sFilePath = @ScriptDir & "\toolbox.txt" ; Percorso del file
Global $iIntervalloMs = 1000 ; Intervallo in millisecondi (1000 ms = 1 secondo)
Global $sLineaDaScrivere = "XUSTEC,845152555,-12"

; === LOOP PRINCIPALE ===
While 1
    ; Cancella il file se esiste
    If FileExists($sFilePath) Then
        FileDelete($sFilePath)
    EndIf

    ; Crea nuovamente il file e scrivi la riga
    Local $hFile = FileOpen($sFilePath, $FO_APPEND)
    If $hFile <> -1 Then
        FileWriteLine($hFile, $sLineaDaScrivere)
        FileClose($hFile)
        ConsoleWrite("[" & _NowTime() & "] File aggiornato." & @CRLF)
    Else
        MsgBox(16, "Errore", "Impossibile creare il file: " & $sFilePath)
    EndIf

    ; Aspetta l'intervallo definito prima di ricominciare
    Sleep($iIntervalloMs)
WEnd

 

Posted (edited)
37 minutes ago, ioa747 said:

you use as style or as exStyle to $gGroupDynamic

Yes that's the reason, for example with a simplified script (Esc to quit the script), have a look at the Console

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

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration
Opt("GUIOnEventMode", 1) ; Event Mode ON

Global $aTradeRows[0]
Global $AllertNotify
Global $gGroupDynamic = 0
ConsoleWrite("$gGroupDynamic = " & $gGroupDynamic & @crlf)

main()

While 1
    Sleep(100)
WEnd

;===========================
Func main()

    ; === GUI ===
    Local $guiWidth = 685, $guiHeight = 40

    $AllertNotify = GUICreate("Trades", $guiWidth, $guiHeight, -1, -1, _
        BitOR($WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS))

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    WinSetOnTop($AllertNotify, "", 1)
    GUISetState(@SW_SHOW)

    LoadTradesFromFile()
    AdlibRegister("ReloadTrades", 3000)
EndFunc

;===========================
Func LoadTradesFromFile()

    Local $symbol = "symbol"
    Local $ticket = "ticket"
    Local $net = "net"

    Local $text = StringFormat("%s | %s", $symbol, $net)
    Local $textSize = StringLen($text) * 7

    ; Associa label e button al gruppo dinamico!
    Local $label = GUICtrlCreateLabel($text, 10, 10, $textSize, 22, 0, $gGroupDynamic)
    ConsoleWrite("$label = " & $label & "   $gGroupDynamic = " & $gGroupDynamic & @crlf)
    _ArrayAdd($aTradeRows, $label)

    Local $btn = GUICtrlCreateButton($ticket, 10 + $textSize, 10, 60, 24, $gGroupDynamic)
    ConsoleWrite("$btn = " & $btn & "   $gGroupDynamic = " & $gGroupDynamic & @crlf)
    GUICtrlSetData($btn, $ticket)
    _ArrayAdd($aTradeRows, $btn)

    Local $tradeCount = 1

    ; Bottone "Chiudi tutto" fuori dal ciclo, associato anch'esso al gruppo
    Local $closeAllBtnX = 685 - 35
    Local $btnCloseAll = GUICtrlCreateButton("X", $closeAllBtnX + 10, 5, 20, 20, $gGroupDynamic)
    ConsoleWrite("$btnCloseAll = " & $btnCloseAll & "   $gGroupDynamic = " & $gGroupDynamic & @crlf & @crlf)

    Return $tradeCount
EndFunc

;===========================
Func ReloadTrades()
    If $gGroupDynamic Then GUICtrlDelete($gGroupDynamic) ; cancella il contenitore

    $gGroupDynamic = GUICtrlCreateGroup("", 0, 0, 685, 30) ; contenitore invisibile
    ConsoleWrite("$gGroupDynamic = " & $gGroupDynamic & @crlf)
    GUICtrlSetState($gGroupDynamic, $GUI_HIDE)

    ReDim $aTradeRows[0]
    LoadTradesFromFile()

    GUICtrlSetState($gGroupDynamic, $GUI_SHOW)
EndFunc

;===========================
Func _Exit()
    Exit
EndFunc

 

$gGroupDynamic = 0
$label = 3   $gGroupDynamic = 0
$btn = 4   $gGroupDynamic = 0
$btnCloseAll = 5   $gGroupDynamic = 0

$gGroupDynamic = 6
$label = 7   $gGroupDynamic = 6
$btn = 8   $gGroupDynamic = 6
$btnCloseAll = 9   $gGroupDynamic = 6

$gGroupDynamic = 6
$label = 10   $gGroupDynamic = 6
$btn = 11   $gGroupDynamic = 6
$btnCloseAll = 12   $gGroupDynamic = 6

You apply the value of $gGroupDynamic to your 3 controls, in Style or ExStyle and it creates a mess.
For example, see how a value of 6 changes the button style in this script, turning it to a checkbox :

#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25) ; ok
    Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25, 6) ; Style 2 to 7 => checkbox, style 10 hides etc...

    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_Close
                ExitLoop
        EndSwitch
    WEnd

    GUIDelete($hGUI)
EndFunc   ;==>Example

 

Edited by pixelsearch
typo

"I think you are searching a bug where there is no bug... don't listen to bad advice."

  • Melba23 changed the title to autoit problem

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
  • Recently Browsing   0 members

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