Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Refresh Gui


  • Please log in to reply
4 replies to this topic

#1 StungStang

StungStang

    Polymath

  • Active Members
  • PipPipPipPip
  • 245 posts

Posted 29 March 2011 - 08:27 PM

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 :

Plain Text         
#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, 29 March 2011 - 08:28 PM.








#2 bogQ

bogQ

    For me, it’s simple - it’s a way of life.

  • Active Members
  • PipPipPipPipPipPip
  • 1,847 posts

Posted 29 March 2011 - 08:33 PM

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, 29 March 2011 - 08:42 PM.

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.

 


#3 UEZ

UEZ

    Never say never

  • MVPs
  • 4,969 posts

Posted 29 March 2011 - 09:59 PM

Here a fast hack:

AutoIt         
#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, 29 March 2011 - 10:15 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#4 StungStang

StungStang

    Polymath

  • Active Members
  • PipPipPipPip
  • 245 posts

Posted 30 March 2011 - 07:30 PM

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!

#5 bogQ

bogQ

    For me, it’s simple - it’s a way of life.

  • Active Members
  • PipPipPipPipPipPip
  • 1,847 posts

Posted 30 March 2011 - 09:03 PM

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, 30 March 2011 - 09:07 PM.

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.

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users