Jump to content

Refresh Gui


Recommended Posts

Hi to all, i want made a multilang programm...all work good...now i want refresh the main gui language but it work only on second gui.

This is my code :

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

Dim $LangArray[1000]

_Lang()

$hGUI = GUICreate("Lang", 159, 69, 192, 124)
$Label1 = GUICtrlCreateLabel($LangArray[1], 8, 8, 140, 17)
$Lang = GUICtrlCreateButton("Change", 40, 32, 75, 25)
GUISetState()


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Lang
            GUISetState(@SW_DISABLE, $hGUI)
            gui2()
            GUISetState(@SW_ENABLE, $hGUI)
            WinActivate ($hGUI)
            ;I want to refresh the gui :)

    EndSwitch
WEnd


Func Gui2()
$hGUI2 = GUICreate("Lang!", 163, 69, 192, 124)
$EN = GUICtrlCreateButton("EN", 16, 32, 35, 25)
$IT = GUICtrlCreateButton("IT", 64, 32, 35, 25)
$ES = GUICtrlCreateButton("ES", 112, 32, 35, 25)
$Label1 = GUICtrlCreateLabel($LangArray[2], 8, 8, 148, 17)
GUISetState()

While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($hGUI2)
                ExitLoop
            Case $EN
                IniWrite(@ScriptDir & "\Language.ini", "Current Language", "Lang", "EN")
                GUIDelete($hGUI2)
                _Lang()
                ExitLoop
            Case $IT
                IniWrite(@ScriptDir & "\Language.ini", "Current Language", "Lang", "IT")
                GUIDelete($hGUI2)
                ExitLoop
                _Lang()
            Case $ES
                IniWrite(@ScriptDir & "\Language.ini", "Current Language", "Lang", "ES")
                GUIDelete($hGUI2)
                ExitLoop
                _Lang()
        EndSwitch
WEnd

EndFunc

Func _Lang()
    $CurrentLang = IniRead(@ScriptDir & "\Language.ini", "Current Language", "Lang", "")
    For $l = 1 To 2
        $LangArray[$l] = IniRead(@ScriptDir & "\Language.ini", $CurrentLang, $l, "")
    Next

EndFunc

This is the Language.ini file :

[Current Language]
Lang=EN

[EN]
1=Hello
2=Select your language

[IT]
1=Ciao!
2=Seleziona lingua

[ES]
1=Hola!
2=seleccionar el idioma

I can change language, it work good only on second gui, but on the main gui remains the old language, it dont refresh the new...The main gui language work only if i restart the application, but i dont want to do that :)...

There is a way to refresh the main gui with the new selected language?

Hi!

Edited by StungStang
Link to comment
Share on other sites

Dont recreate guis, hide them when you need to change language

Put one main loop to rule them all and

GUICtrlSetData to change language settings

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Here a fast hack:

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

Global $Label1, $Label2, $EN, $IT, $ES, $current
$aSections = IniReadSectionNames("Language.ini")
Dim $aLanguages[$aSections[0] + 1][100]
$max_w = 0
For $i = 1 To $aSections[0]
    $aLanguages[$i][0] = $aSections[$i]
    $aSectionNames = IniReadSection("Language.ini", $aSections[$i])
    $max_w = Max($max_w, $aSectionNames[0][0])
    For $j = 1 To $aSectionNames[0][0]
        $aLanguages[$i][$j] = $aSectionNames[$j][1]
    Next
Next
ReDim $aLanguages[UBound($aLanguages)][$max_w + 1]
$aLanguages[0][0] = UBound($aLanguages) - 1

$hGUI = GUICreate("Lang", 159, 69, -1, -1, Default, $WS_EX_TOPMOST)
$Label1 = GUICtrlCreateLabel("", 8, 8, 140, 17)
$Lang = GUICtrlCreateButton("Change", 40, 32, 75, 25)
GUISetState(@SW_SHOW, $hGUI)

$hGUI2 = GUICreate("Lang!", 159, 69, -1, -1, Default)
$bEN = GUICtrlCreateButton("EN", 16, 32, 35, 25)
$bIT = GUICtrlCreateButton("IT", 64, 32, 35, 25)
$bES = GUICtrlCreateButton("ES", 112, 32, 35, 25)
$Label2 = GUICtrlCreateLabel("", 8, 8, 148, 17)
GUISetState(@SW_HIDE, $hGUI2)
_Lang($aLanguages[1][1])

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            IniWrite(@ScriptDir & "\Language.ini", "Current Language", "Lang", $current)
            Exit
        Case $Lang
            GUISetState(@SW_HIDE, $hGUI)
            gui2()
            GUISetState(@SW_SHOW, $hGUI)
            WinActivate($hGUI)
            GUISwitch($hGUI)
      EndSwitch
WEnd

Func Gui2()
    GUISetState(@SW_SHOW, $hGUI2)
    WinActivate($hGUI2)
    GUISwitch($hGUI2)
    While 1
            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                Case $bEN
                    _Lang("EN")
                    $current = "EN"
                    ExitLoop
                Case $bIT
                    _Lang("IT")
                    $current = "IT"
                    ExitLoop
                Case $bES
                    _Lang("ES")
                    $current = "ES"
                    ExitLoop
            EndSwitch
    WEnd
    GUISetState(@SW_HIDE, $hGUI2)
EndFunc

Func _Lang($lang)
    Switch $lang
        Case "EN"
            GUICtrlSetData($Label1, $aLanguages[2][1])
            GUICtrlSetData($Label2, $aLanguages[2][2])
        Case "IT"
            GUICtrlSetData($Label1, $aLanguages[3][1])
            GUICtrlSetData($Label2, $aLanguages[3][2])
        Case "ES"
            GUICtrlSetData($Label1, $aLanguages[4][1])
            GUICtrlSetData($Label2, $aLanguages[4][2])
    EndSwitch
EndFunc

Func Max($a, $b)
    If $a > $b Then Return $a
    Return $b
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Dont recreate guis, hide them when you need to change language

Put one main loop to rule them all and

GUICtrlSetData to change language settings

Why in the second gui all work good without do nothing? :)...

Only GuiCtrlSetData work for this job?...

Hi!

Link to comment
Share on other sites

No, recreating your main gui can do that 2 as you did in your demonstration on second gui (you did forgot to demonstrate it on first gui :) ), the thing is GuiCtrlSetData should be easier than recreating whole gui.

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

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