Sign in to follow this  
Followers 0
infernothebest

get or recive date from other while

10 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

boh thx , i was looking for ages for this:) is it possible to get the data anyway? even if it isnt opent

I have no idea what you are trying to say...

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

What do you want the get data button to do? Grab the text that is currently in notepad?

Also... I thought you were wanting to run two separate scripts which is why I suggested Env variables.. since it is 2 guis in the same script we just want to stick to global vars.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

exactly that thx for helping me you are quicker then me reacting hahah thx

Edited by infernothebest

Share this post


Link to post
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
Sign in to follow this  
Followers 0