Jump to content

GUI Focus after Control ( If )


Recommended Posts

Good mornign everyone.

How are you? Hope fine. My today's questione is: "How can I set a focus on a input ( code ) if an error has occured?"

GUICtrlCreateInput

Best explanation... I make a control on $cPath and $cIstances... How can I set a focus on each of them if the control is not passed? And consequently, how can I make loop it until the control is passed? Because I don't want to store the content of $cPath and $cIstances until they don't pass the controls. I tried with create a variable in which store a bit with the "control passed or not", so I can keep this loop but, I know that is not so funcionally as it seems. By the way, thanks again to M23 who has suggested me the ".ini strategy". Thanks to all. I felt in love with this language! :D
 

; ===== Include section =====

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

;===== INI Variables section =====

Local Const $Config = "configurazione.ini"
Local Const $cSection = "CONFIG"
Local Const $cKey1 = "PATH"
Local Const $cKey2 = "ISTANCES"
Local $cKeyValue1 = "", $cKeyValue2 = "", $cPath, $cIstances, $CheckPath, $CheckIstances

;===== Does the .ini file exist? =====

If NOT FileExists($Config) Then
    IniWrite($Config, $cSection, $cKey1, $cKeyValue1)
    IniWrite($Config, $cSection, $cKey2, $cKeyValue2)
Else
    $cPath     = IniRead($Config, $cSection, $cKey1, "-1")
    $cIstances = IniRead($Config, $cSection, $cKey2, "-1")

;===== GUI Creation =====

    $Form = GUICreate("MULTISCREEN",300,130)
    Local $Label1 = GUICtrlCreateLabel("Percorso:",10,10,280,20)
    Local $Input1 = GUICtrlCreateInput($cPath,10,30,280,20)
    Local $Label2 = GUICtrlCreateLabel("Istanze:",10,55,280,20)
    Local $Input2 = GUICtrlCreateInput($cIstances,10,75,40,20)
    Local $Label3 = GUICtrlCreateLabel("Scrivi il numero di volte che il programma dev'essere lanciato",52.5,72.5,280,30)
    Local $Button1 = GUICtrlCreateButton("Salva",200,100,40,20)
    Local $Button2 = GUICtrlCreateButton("Invia",250,100,40,20)

    While 1
        GUISetState(@SW_SHOW)
        Switch GUIGetMsg()
            Case $Button1
                $cPath = GUICtrlRead($Input1,0)
                $cIstances = GUICtrlRead($Input2,0)
                Do
                    If StringIsAlNum($cPath) = 0 Then
                        MsgBox($MB_ICONERROR,"ERRORE!","Il testo inserito non è alfanumerico." & @CRLF & "Inserire un indirizzo valido.")
                        $CheckPath = 0
                    Else
                        $CheckPath = 1
                    EndIf
                Until $CheckPath = 1
                Do
                    If StringIsInt($cIstances) = 0 Then
                        MsgBox($MB_ICONERROR, "ERRORE","Il valore inserito non è intero." & @CRLF & "Inserire un numero valido.")
                        $CheckIstances = 0
                    Else
                        If $cIstances < 2 OR $cIstances > 4 Then
                            MsgBox($MB_ICONERROR, "ERRORE!", "Il numero non può essere minore di 2 o più grande di 4." & @CRLF & "Inserire un numero valido.")
                            $CheckIstances = 0
                        EndIf
                    EndIf
                Until $CheckIstances = 1
                IniWrite($Config, $cSection, $cKey1, $cPath)
                IniWrite($Config, $cSection, $cKey2, $cIstances)
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndIf

 

 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • Moderators

FrancesoDiMuro,

Something like this should work:

While 1
    GUISetState(@SW_SHOW)
    Switch GUIGetMsg()
        Case $Button1
            $cPath = GUICtrlRead($Input1, 0)
            $cIstances = GUICtrlRead($Input2, 0)
            If StringIsAlNum($cPath) = 0 Then
                MsgBox($MB_ICONERROR, "ERRORE!", "Il testo inserito non è alfanumerico." & @CRLF & "Inserire un indirizzo valido.")
                GUICtrlSetState($Input1, $GUI_FOCUS)
            Else
                If StringIsInt($cIstances) = 0 Then
                    MsgBox($MB_ICONERROR, "ERRORE", "Il valore inserito non è intero." & @CRLF & "Inserire un numero valido.")
                    GUICtrlSetState($Input2, $GUI_FOCUS)
                Else
                    MsgBox(0, "CHECKED", "Writing to ini file")
                    ;IniWrite($Config, $cSection, $cKey1, $cPath)
                    ;IniWrite($Config, $cSection, $cKey2, $cIstances)
                EndIf
            EndIf

        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

M23

Edit: Sorry - forgot the focus bit.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks a lot M23. "The script works like a champ!" ( Cit. from a thread I've read over this forum! )

Just another question. I have to "send" the istances of the program I launch to several screens ( 4 screens )... I thought that I could do this with the Windows Key Combination "Shift + WinKey + Right Arrow ( or left )", sending them with the function Send() that made me discover this wonderful language. I thought something like this:

$Index = 0 ; Indice che viene incrementato ogni qualvolta viene aperta un'istanza del file FileCheDeveEssereAperto.txt
    Do
        ShellExecute($sFileName & $sExtension, "", $sDrive & $sDir)
        Sleep(2000)
        Switch $Index
            Case 1
                Send("+#{Right}") ; 2° Schermo - Combinazione di tasti che il programma "invia" al computer, la quale combinazione permette di shiftare la schermata verso destra ( per multischermi, schermi estesi! )
            Case 2
                Send("+#{Right}{Right}") ; 3° Schermo
            Case 3
                Send("+#{Right}{Right}{Right}") ; {Right}{Right}{Right} ; 4° Schermo
        EndSwitch
        $Index += 1
    Until $Index = $Line2
    EndSwitch

Tell me if it could be correct or it can be improved. I don't know how to say thank you, literally! :D

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • Moderators

FrancescoDiMuro,

I would do it like this  - using AutoIt to count the loop rather then doing it in the code:

For $Index = 1 To $Line2 ; Indice che viene incrementato ogni qualvolta viene aperta un'istanza del file FileCheDeveEssereAperto.txt

    ShellExecute($sFileName & $sExtension, "", $sDrive & $sDir)
    Sleep(2000)
    Switch $Index
        Case 1
            Send("+#{Right}") ; 2° Schermo - Combinazione di tasti che il programma "invia" al computer, la quale combinazione permette di shiftare la schermata verso destra ( per multischermi, schermi estesi! )
        Case 2
            Send("+#{Right}{Right}") ; 3° Schermo
        Case 3
            Send("+#{Right}{Right}{Right}") ; {Right}{Right}{Right} ; 4° Schermo
    EndSwitch
Next

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

FrancescoDiMuro,

As we have no idea what program you are running and how it reacts, how can we answer? WinMove might well be another solution worth investigating.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...