Jump to content

get or recive date from other while


Recommended Posts

if i make a second gui in my first gui how can i comunnicate between the gui's, lets say string data?

i add a little example with the button get data i wanna gt the data from the second gui

#include <GUIConstantsEx.au3>
    GUICreate("My GUI") 
    GUISetState(@SW_SHOW) 
$Button_1 = GUICtrlCreateButton("Run Notepad", 10, 30, 100)
$Button_2 = GUICtrlCreateButton("get data", 150, 30, 100)

    While 1
        $msg = GUIGetMsg()
if $msg =$Button_2 then
    msgbox(0,"",$stringdata)
    endif


        
if $msg = $Button_1 Then
secondgui()
    EndIf
    
    
    
    
    
        If $msg = $GUI_EVENT_CLOSE Then Exit
    WEnd
  
Func secondgui()
GUICreate("second GUI")
$stringdata=GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, 70)
GUISetState(@SW_SHOW) 
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
 WEnd
EndFunc
Edited by infernothebest
Link to comment
Share on other sites

There are many ways to do this, but a simple way would be like this:

#include <GUIConstantsEx.au3>
EnvSet('StringData', 'Nothing yet.')
Global $stringdata, $SecondGUI
$mainGUI = GUICreate("My GUI")
GUISetState(@SW_SHOW)
$Button_1 = GUICtrlCreateButton("Run Notepad", 10, 30, 100)
$Button_2 = GUICtrlCreateButton("get data", 150, 30, 100)

While 1
    $msg = GUIGetMsg(1)
    If $msg[0] = $Button_2 Then
        MsgBox(0, "", EnvGet('StringData'))
    EndIf
    If $msg[0] = $Button_1 Then
        secondgui()
    EndIf
    If $msg[0] = $GUI_EVENT_CLOSE and $msg[1] = $mainGUI Then Exit
    If $msg[0] = $GUI_EVENT_CLOSE and $msg[1] = $SecondGUI Then GUIDelete($SecondGUI)
WEnd

Func secondgui()
    $SecondGUI = GUICreate("second GUI")
    $stringdata = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, 70)
    GUISetState(@SW_SHOW)
    If GUICtrlRead($stringdata) <> EnvGet('StringData') Then EnvSet('StringData', GUICtrlRead($stringdata))
EndFunc   ;==>secondgui
Link to comment
Share on other sites

nevermind got it, i dont know how you do it without 2 while's because you got 2 gui's can you explain a litlle bit? i made a extra button on the other gui if you can make this working then i think i understand

#include <GUIConstantsEx.au3>
EnvSet('StringData', 'Nothing yet.')
Global $stringdata, $SecondGUI
$mainGUI = GUICreate("My GUI")
GUISetState(@SW_SHOW)
$Button_1 = GUICtrlCreateButton("other gui", 10, 30, 100)
$Button_2 = GUICtrlCreateButton("get data", 150, 30, 100)

While 1
$msg = GUIGetMsg(1)
If $msg[0] = $Button_2 Then
MsgBox(0, "", EnvGet('StringData'))
EndIf
If $msg[0] = $Button_1 Then
run("notepad.exe")
EndIf

If $msg[0] = $Button_1 Then
secondgui()
EndIf
If $msg[0] = $GUI_EVENT_CLOSE and $msg[1] = $mainGUI Then Exit
If $msg[0] = $GUI_EVENT_CLOSE and $msg[1] = $SecondGUI Then GUIDelete($SecondGUI)
WEnd

Func secondgui()
$SecondGUI = GUICreate("second GUI")
$stringdata = GUICtrlCreateLabel("Line 1 Cell 1", 10, 30, 70)
$Button_3 = GUICtrlCreateButton("Run Notepad", 10, 30, 100)
GUISetState(@SW_SHOW)
If GUICtrlRead($stringdata) <> EnvGet('StringData') Then EnvSet('StringData', GUICtrlRead($stringdata))
EndFunc ;==>secondgui
Edited by infernothebest
Link to comment
Share on other sites

Are you just needing a global variable?

#include <GUIConstantsEx.au3>
Global $stringdata, $SecondGUI, $data = 'is this what you mean? there is still information here but no GUI.'
$mainGUI = GUICreate("My GUI")
GUISetState(@SW_SHOW)
$Button_1 = GUICtrlCreateButton("Run Notepad", 10, 30, 100)
$Button_2 = GUICtrlCreateButton("get data", 150, 30, 100)

While 1
    $msg = GUIGetMsg(1)
    If $msg[0] = $Button_2 Then
        MsgBox(0, "", $data)
    EndIf
    If $msg[0] = $Button_1 Then
        secondgui()
    EndIf
    If $msg[0] = $GUI_EVENT_CLOSE and $msg[1] = $mainGUI Then Exit
    If $msg[0] = $GUI_EVENT_CLOSE and $msg[1] = $SecondGUI Then
        $data = 'is this what you mean? there is still information here but no GUI.'
        GUIDelete($SecondGUI)
    EndIf
WEnd

Func secondgui()
    $SecondGUI = GUICreate("second GUI")
    $data = 'GUI'
    $stringdata = GUICtrlCreateLabel($data, 10, 30, 70)
    GUISetState(@SW_SHOW)
EndFunc   ;==>secondgui
Link to comment
Share on other sites

If I understand what you want, which I am starting to doubt...

#include <GUIConstantsEx.au3>
Global $stringdata, $SecondGUI, $Button_3, $data
$mainGUI = GUICreate("My GUI")
GUISetState(@SW_SHOW)
$Button_1 = GUICtrlCreateButton("other gui", 10, 30, 100)
$Button_2 = GUICtrlCreateButton("get data", 150, 30, 100)

While 1
    $msg = GUIGetMsg(1)
    If $msg[0] = $Button_2 Then
        MsgBox(0, "", $data)
    EndIf
    If $msg[0] = $Button_3 And $msg[0] <> 0 Then
        Run("notepad.exe")
    EndIf

    If $msg[0] = $Button_1 Then
        secondgui()
    EndIf
    If $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $mainGUI Then Exit
    If $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $SecondGUI Then GUIDelete($SecondGUI)
    If GUICtrlRead($stringdata) <> $data Then $data = GUICtrlRead($stringdata)
WEnd

Func secondgui()
    $SecondGUI = GUICreate("second GUI")
    $stringdata = GUICtrlCreateLabel("Line 1 Cell 1", 10, 100, 70)
    $Button_3 = GUICtrlCreateButton("Run Notepad", 10, 30, 100)
    GUISetState(@SW_SHOW)
EndFunc   ;==>secondgui
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...