Jump to content

Label update from another GUI


Recommended Posts

Use GUISwitch to make the operations act on the Child GUI, then use GUICtrlSetData to change text of the Label

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Use GUISwitch to make the operations act on the Child GUI, then use GUICtrlSetData to change text of the Label

Could you do me a little quick script example?

#include 

_Main()

Func _Main()

;Initialize variables
Local $GUIWidth = 250, $GUIHeight = 250
Local $ParentWin, $ParentWin_Pos, $ChildWin, $msg

;Create main/parent window
$ParentWin = GUICreate("Parent GUI", $GUIWidth, $GUIHeight)
$Label_1 = GUICtrlCreateLabel("Label 1", 30, 40, 131, 21, 0x1000)
$Label_1 = GUICtrlCreateLabel("Label 2", 30, 110, 131, 21, 0x1000)

;Save the position of the parent window
$ParentWin_Pos = WinGetPos($ParentWin, "")
;Show the parent window/Make the parent window visible
GUISetState(@SW_SHOW)

;Create child window and add the parameter to make it the child of the parent window
$ChildWin = GUICreate("Child GUI", $GUIWidth, $GUIHeight, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $ParentWin)
$Label_1 = GUICtrlCreateLabel("Label 1", 30, 40, 131, 21, 0x1000)
$Label_2 = GUICtrlCreateLabel("Label 2", 30, 90, 131, 21, 0x1000)
$Combo_2 = GUICtrlCreateCombo("", 30, 60, 130, 21)
$Combo_3 = GUICtrlCreateCombo("", 30, 110, 130, 21)
GUICtrlSetData($Combo_2, "Item1|Item2|Item3|Item4|Item5")
$button1 = GUICtrlCreateButton("Update (Set Labels)", 30, 200, 130, 20)



;Show the child window/Make the child window visible
GUISetState(@SW_SHOW)

;Switch to the parent window
GUISwitch($ParentWin)

;Loop until:
;- user presses Esc when focused to the parent window
;- user presses Alt+F4 when focused to the parent window
;- user clicks the close button of the parent window
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
;When button is pressed, label text is changed
;to combobox value
Case $msg = $button1
$data = GUICtrlRead($Combo_2)
GUICtrlSetData($Label_1, $data)
EndSelect
WEnd
EndFunc ;==>_Main
Edited by Crysis
Link to comment
Share on other sites

You're reusing the variable names for the second GUI's labels, you're destroying any link back to the first set of labels by reusing them. Change the label variable names in one of the GUI's and update the correct labels with the GUICtrlSetData.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Seriously? You can't figure out what I meant when I said that you can't reuse the variable name $Label_1 for 3 different labels and expect the code to work? Rename 2 of those variables to anything else, as long as they aren't renamed to the same name. Then make sure your GUICtrlSetData is using the variable that is assigned to the correct label you want to update the contents of.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

#include 

_Main()

Func _Main()

;Initialize variables
Local $GUIWidth = 250, $GUIHeight = 250
Local $ParentWin, $ParentWin_Pos, $ChildWin, $msg

;Create main/parent window
$ParentWin = GUICreate("Parent GUI", $GUIWidth, $GUIHeight)
$Label1 = GUICtrlCreateLabel("N/A", 30, 40, 131, 21, 0x1000)
$Label2 = GUICtrlCreateLabel("N/A", 30, 110, 131, 21, 0x1000)

;Save the position of the parent window
$ParentWin_Pos = WinGetPos($ParentWin, "")
;Show the parent window/Make the parent window visible
GUISetState(@SW_SHOW)

;Create child window and add the parameter to make it the child of the parent window
$ChildWin = GUICreate("Child GUI", $GUIWidth, $GUIHeight, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $ParentWin)
$Label_1 = GUICtrlCreateLabel("N/A", 30, 40, 131, 21, 0x1000)
$Label_2 = GUICtrlCreateLabel("N/A", 30, 90, 131, 21, 0x1000)
$Combo_2 = GUICtrlCreateCombo("", 30, 60, 130, 21)
$Combo_3 = GUICtrlCreateCombo("", 30, 110, 130, 21)
GUICtrlSetData($Combo_2, "50|49|48|47|46")
GUICtrlSetData($Combo_3, "50|49|48|47|46")
$button1 = GUICtrlCreateButton("Update (Set Labels)", 30, 200, 130, 20)



;Show the child window/Make the child window visible
GUISetState(@SW_SHOW)

;Switch to the parent window
GUISwitch($ParentWin)

;Loop until:
;- user presses Esc when focused to the parent window
;- user presses Alt+F4 when focused to the parent window
;- user clicks the close button of the parent window
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
;When button is pressed, label text is changed
;to combobox value
Case $msg = $button1
$data = GUICtrlRead($Combo_2)
GUICtrlSetData($Label_1, $data)
GUICtrlSetData($Label1, $data)

$data = GUICtrlRead($Combo_3)
GUICtrlSetData($Label_2, $data)
GUICtrlSetData($Label2, $data)





EndSelect
WEnd
EndFunc ;==>_Main

Link to comment
Share on other sites

You should use the advanced mode of GUIGetMsg to avoid any further errors,

look at the function in the help file.

Example

#include <GUIConstantsEx.au3>

_Main()

Func _Main()

;Initialize variables
Local $GUIWidth = 250, $GUIHeight = 250
Local $ParentWin, $ParentWin_Pos, $ChildWin, $msg

;Create main/parent window
$ParentWin = GUICreate("Parent GUI", $GUIWidth, $GUIHeight)
$Label1 = GUICtrlCreateLabel("N/A", 30, 40, 131, 21, 0x1000)
$Label2 = GUICtrlCreateLabel("N/A", 30, 110, 131, 21, 0x1000)

;Save the position of the parent window
$ParentWin_Pos = WinGetPos($ParentWin, "")
;Show the parent window/Make the parent window visible
GUISetState(@SW_SHOW)

;Create child window and add the parameter to make it the child of the parent window
$ChildWin = GUICreate("Child GUI", $GUIWidth, $GUIHeight, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $ParentWin)
$Label_1 = GUICtrlCreateLabel("N/A", 30, 40, 131, 21, 0x1000)
$Label_2 = GUICtrlCreateLabel("N/A", 30, 90, 131, 21, 0x1000)
$Combo_2 = GUICtrlCreateCombo("", 30, 60, 130, 21)
$Combo_3 = GUICtrlCreateCombo("", 30, 110, 130, 21)
GUICtrlSetData($Combo_2, "50|49|48|47|46")
GUICtrlSetData($Combo_3, "50|49|48|47|46")
$button1 = GUICtrlCreateButton("Update (Set Labels)", 30, 200, 130, 20)



;Show the child window/Make the child window visible
GUISetState(@SW_SHOW)

;Switch to the parent window
GUISwitch($ParentWin)

;Loop until:
;- user presses Esc when focused to the parent window
;- user presses Alt+F4 when focused to the parent window
;- user clicks the close button of the parent window
While 1
$msg = GUIGetMsg(1)
Switch $msg[1]
Case $ChildWin
;ChildWin MsgLoop

Switch $msg[0]
Case $GUI_EVENT_CLOSE
ExitLoop
;When button is pressed, label text is changed
;to combobox value
Case $button1
$data = GUICtrlRead($Combo_2)
;~  GUICtrlSetData($Label_1, $data)
GUICtrlSetData($Label1, $data)

$data = GUICtrlRead($Combo_3)
;~  GUICtrlSetData($Label_2, $data)
GUICtrlSetData($Label2, $data)
EndSwitch

EndSwitch
WEnd
EndFunc   ;==>_Main

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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