Jump to content

help making 2 guis at the same time


BasicOs
 Share

Recommended Posts

I mean: I need to get input from any, as coded now ... it wait for input in frmgui2() and frmgui1() is not working as I made a timer inside

frmgui1()

frmgui2()

func frmgui1()

###koda

bla bla

####koda

frmgui2()

switch

case

case

endswitch

timer()

endfunc

func frmgu2()

###koda

bla bla

####koda

switch

case

case

endswitch

endfunc

thanks I am trying guis in the last days

Edited by BasicOs
Autoit.es - Foro Autoit en Español Word visitors Image Clustrmap image: - Football Spanish team - Spanish team: Casillas, Iniesta, Villa, Xavi, Puyol, Campdevilla, etc..Programando en Autoit+Html - Coding Autoit-Html - Arranca programas desde Internet - Preprocesador de Autoit a http
Link to comment
Share on other sites

Don't understand what you want from your description but if you want 2 forms and to know what is done on either form why can't you do something as simple as this?

#include <GuiConstants.au3>

$w1 = guicreate("form 1",200,200,10,10)
$b1w1 = GUICtrlCreateButton("b1",10,10,50,18)

GUISetState()

$w2 = guicreate("form 2",200,200,250,10)
$b2w2 = GUICtrlCreateButton("b2",10,10,50,18)

GUISetState()

while 1
$msg = GUIGetMsg()
if $msg = $b1w1 then msgbox(0,'','Button on form 1 pressed')
if $msg = $b2w2 then msgbox(0,'','Button on form 2 pressed')
if $msg = $GUI_EVENT_CLOSE Then ExitLoop    
WEnd

Presumably you want something different but you will need to explain it better for me to understand or give us some code.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

@martin thank you, great I will try

but if you want to have a gui as option of the first gui and still should chooose from the first

i mean when you press gui1 can you get feed back from parent gui?

#include <GuiConstants.au3>
gui1()
$w2 = guicreate("form 2",200,200,250,10)
$b2w2 = GUICtrlCreateButton("b2",10,10,50,18)

GUISetState()

while 1
$msg = GUIGetMsg()
if $msg = $b1w1 then gui1()
if $msg = $b2w2 then msgbox(0,'','Button on form 2 pressed')
if $msg = $GUI_EVENT_CLOSE Then ExitLoop    
WEnd


func gu1
$w1 = guicreate("form 1",200,200,10,10)
$b1w1 = GUICtrlCreateButton("b1",10,10,50,18)

GUISetState()
endfunc

Don't understand what you want from your description but if you want 2 forms and to know what is done on either form why can't you do something as simple as this?

#include <GuiConstants.au3>

$w1 = guicreate("form 1",200,200,10,10)
$b1w1 = GUICtrlCreateButton("b1",10,10,50,18)

GUISetState()

$w2 = guicreate("form 2",200,200,250,10)
$b2w2 = GUICtrlCreateButton("b2",10,10,50,18)

GUISetState()

while 1
$msg = GUIGetMsg()
if $msg = $b1w1 then msgbox(0,'','Button on form 1 pressed')
if $msg = $b2w2 then msgbox(0,'','Button on form 2 pressed')
if $msg = $GUI_EVENT_CLOSE Then ExitLoop    
WEnd

Presumably you want something different but you will need to explain it better for me to understand or give us some code.

Autoit.es - Foro Autoit en Español Word visitors Image Clustrmap image: - Football Spanish team - Spanish team: Casillas, Iniesta, Villa, Xavi, Puyol, Campdevilla, etc..Programando en Autoit+Html - Coding Autoit-Html - Arranca programas desde Internet - Preprocesador de Autoit a http
Link to comment
Share on other sites

Still not sure I understand what you want but does this help

#include <GuiConstants.au3>
$w2 = guicreate("form 2",200,200,250,10)
$b2w2 = GUICtrlCreateButton("b2",10,10,50,18)
$b3w2 = GUICtrlCreateButton("make gui2",10,40,50,18)
$b1w1 = 0
GUISetState()

while 1
$msg = GUIGetMsg()
if $msg = $b3w2 then gu1()
if $msg = $b2w2 then msgbox(0,'','Button on form 2 pressed')
if $b1w1 and $msg = $b1w1 then MsgBox(0,'','Button on from 1 pressed')
if $msg = $GUI_EVENT_CLOSE Then ExitLoop    
WEnd


func gu1()
$w1 = guicreate("form 1",200,200,10,10)
$b1w1 = GUICtrlCreateButton("b1",10,10,50,18)
GUICtrlSetState($b3w2,$GUI_HIDE)
GUISetState()
endfunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

that is,

well till now i was used that each form shoul keep its own quee from msg, I mean if you could make two:

call all guis

while 1
$msg = GUIGetMsg()
if $msg = $b3w2 then gu1()
if $msg = $b2w2 then msgbox(0,'','Button on form 2 pressed')
if $msg = $GUI_EVENT_CLOSE Then ExitLoop    
WEnd

while 1
$msg = GUIGetMsg()
if $b1w1 then MsgBox(0,'','Button on from 1 pressed')
if $msg = $GUI_EVENT_CLOSE Then ExitLoop    
WEnd

one for each programm and both separate, I mean if it is necesary to unify the quees of all guis working at this moment to resolve the guigetmsg or is it possible to multi thread that

I mean each while could work for its own

thanks for answers

Autoit.es - Foro Autoit en Español Word visitors Image Clustrmap image: - Football Spanish team - Spanish team: Casillas, Iniesta, Villa, Xavi, Puyol, Campdevilla, etc..Programando en Autoit+Html - Coding Autoit-Html - Arranca programas desde Internet - Preprocesador de Autoit a http
Link to comment
Share on other sites

To save any more guesswork, can you give a simple description of what you want to achieve?

If you want the second form top be started and then run independantly of the first one then could you have a separate script for each form.

Form2 > compile to F2.exe

form1

.

.

.code

.

if $startform2 then Run("F2.EXE") ;or RunWait(....

.

.

.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I like this solution, but is there a way to know where $msg = $GUI_EVENT_CLOSE comes from by closing on form or the other,

I mean when the if $msg = $GUI_EVENT_CLOSE event happens in this moment you close both, really there is a parent one and a child one. and when you close the child one, the parent should not close

thanks

Don't understand what you want from your description but if you want 2 forms and to know what is done on either form why can't you do something as simple as this?

#include <GuiConstants.au3>

$w1 = guicreate("form 1",200,200,10,10)
$b1w1 = GUICtrlCreateButton("b1",10,10,50,18)

GUISetState()

$w2 = guicreate("form 2",200,200,250,10)
$b2w2 = GUICtrlCreateButton("b2",10,10,50,18)

GUISetState()

while 1
$msg = GUIGetMsg()
if $msg = $b1w1 then msgbox(0,'','Button on form 1 pressed')
if $msg = $b2w2 then msgbox(0,'','Button on form 2 pressed')
if $msg = $GUI_EVENT_CLOSE Then ExitLoop    
WEnd

Presumably you want something different but you will need to explain it better for me to understand or give us some code.

Autoit.es - Foro Autoit en Español Word visitors Image Clustrmap image: - Football Spanish team - Spanish team: Casillas, Iniesta, Villa, Xavi, Puyol, Campdevilla, etc..Programando en Autoit+Html - Coding Autoit-Html - Arranca programas desde Internet - Preprocesador de Autoit a http
Link to comment
Share on other sites

Wow, i have learned sooo much from this one thread.. anyway, for the close only the child:

from gui example folder:

#include <GUIConstants.au3>

;Initialize variables
Global $IniFile
Global $GUIWidth
Global $GUIHeight

$GUIWidth = 250
$GUIHeight = 250

;Create main/parent window
$ParentWin = GUICreate("Parent GUI", $GUIWidth, $GUIHeight)
;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)
;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
  ;After every loop check if the user clicked something in the GUI windows
   $msg = GUIGetMsg(1)
   Select
     ;Check if user clicked on a close button of any of the 2 windows
      Case $msg[0] = $GUI_EVENT_CLOSE
        ;Check if user clicked on the close button of the child window
         If $msg[1] = $ChildWin Then
            MsgBox(64, "Test", "Child GUI will now close.")
           ;Switch to the child window
            GUISwitch($ChildWin)
           ;Destroy the child GUI including the controls
            GUIDelete()
        ;Check if user clicked on the close button of the parent window
         ElseIf $msg[1] = $ParentWin Then
            MsgBox(64, "Test", "Parent GUI will now close.")
           ;Switch to the parent window
            GUISwitch($ParentWin)
           ;Destroy the parent GUI including the controls
            GUIDelete()
           ;Exit the script
            Exit
         EndIf

   EndSelect

WEnd
Edited by MethodZero

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Link to comment
Share on other sites

Untested code:

$aMsg = GUIGetMsg ( 1 )
If $aMsg[1] = $w1 Then
    ; Handel events regarding window 1
ElseIf $aMsg[1] = $w2 Then
    ; Handel events regarding window 2
Else
    ; Hmm, probably a control of some sort :)
EndIf
Link to comment
Share on other sites

I think this is what you want....

#include <GuiConstants.au3>
Global $w2

$w2 = guicreate("form 2",200,200,250,10)
$b2w2 = GUICtrlCreateButton("b2",10,10,50,18)
$b3w2 = GUICtrlCreateButton("make gui2",10,40,50,18)
GUISetState()

while 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case $b3w2          
            GUIDelete(gu1())            
        Case $b2w2
            msgbox(0,'','Button on form 2 pressed')
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

func gu1()
    $w1 = guicreate("form 1",200,200,10,10,-1, -1, $w2)
    $b1w1 = GUICtrlCreateButton("b1",10,10,50,18)
    GUICtrlSetState($b3w2,$GUI_HIDE)
    GUISetState()
    While 1
        $msg = GUIGetMsg(1)
        Switch $msg[0]
            Case $GUI_EVENT_CLOSE
                GUICtrlSetState($b3w2,$GUI_SHOW)
                If $msg[1] = $w2 Then Exit
                Return($w1)
            Case $b1w1
                MsgBox(0,'','Button on from 1 pressed')
        EndSwitch       
    WEnd
endfuncoÝ÷ Ø l¢'ò¢ìÛhºÇ:jºFP§÷§´Êz«¨·_ÛÊj{¬y§îËb¢yb殶­sdgVæ24Äõ4T6Æ6¶VB¢buTõtääDÄRÓÒb33c¶ÖåvæF÷rFVà¢W@¢VÇ6P¢uTFVÆWFRuTõtääDÄR¢VæD`¤VæDgVæ2³ÓÒfwC´4Äõ4T6Æ6¶V

Take a look to this post.

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

NOW i got it

It is possible that way. I start having fun with Gui,

Thank you very much

It was the parameter for getmsg(1) and the array game for picking up input,

Autoit.es - Foro Autoit en Español Word visitors Image Clustrmap image: - Football Spanish team - Spanish team: Casillas, Iniesta, Villa, Xavi, Puyol, Campdevilla, etc..Programando en Autoit+Html - Coding Autoit-Html - Arranca programas desde Internet - Preprocesador de Autoit a http
Link to comment
Share on other sites

@BasicOS

MethodZero, and Danny35d have provided you with excellent solutions, even Uten's is pretty good in concept.

This is what I would use. I dont like the extra checks needed for a multi GUI under the GetMsgMode. Use OnEventMode, with the following template. It has everything you need for multiple GUI's.

Create your main GUI in the top of the script as usual, and any secondary or tertiary GUI's make them in functions.

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;Program Name:  Template - OnEventMode
;Description:   Template for OnEventMode GUI scripts
;Filename:      Template - OnEventMode.au3
;Used With:     
;Created by:    Jarvis J Stubblefield (support "at" vortexrevolutions "dot" com)
;Created on:    06/20/2006
;Modified on:   
;Modified by:   
;Version:       0.0.2
;Copyright:     Copyright (C) 2006 Vortex Revolutions. All Rights Reserved.
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Declare Variables ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Global $wHeight, $wWidth, $wMain            ;Window variables
Global $wTitle                              ;Window variables II

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Preprocessor ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1) ;Set GUI to ONEvent Mode.

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** File Installations ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Registry Information ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Command Line Options ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#cs UNCOMMENT FOR COMMANDLINE!
If $CmdLine[0] > 0 Then
    If StringRight($CmdLine[1], 4) = ".ext" Then
        _SomeFunc($CmdLine[1])
    Else
        _ErrorMsg("Incorret file extension. Please try again.")
        _TerminateApp()
    EndIf
EndIf
#ce

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Define Variables ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$wHeight = 300
$wWidth  = 300
$wTitle  = "Template - OnEventMode"

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Creation ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;Main GUI Creation
$wMain  = GUICreate($wTitle, $wWidth, $wHeight)
;Main Options
$btnMOptions    = GUICtrlCreateButton("Options", 5, ($wHeight - 25), 94, 20)
;Main Help
$btnMHelp       = GUICtrlCreateButton("Help", 103, ($wHeight - 25), 94, 20)
;Main Exit
$btnMExit       = GUICtrlCreateButton("Exit", 201, ($wHeight - 25), 94, 20)

;Disable Options and Help until added
GUICtrlSetState($btnMOptions, $GUI_DISABLE)
GUICtrlSetState($btnMHelp, $GUI_DISABLE)

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Set Events ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;GUI Events Handled by _GUIEventHandler()
GUICtrlSetOnEvent($btnMOptions, "_GUIEventHandler")
GUICtrlSetOnEvent($btnMExit, "_GUIEventHandler")
GUICtrlSetOnEvent($btnMHelp, "_GUIEventHandler")

;System Events Handled by _SysEventHandler()
GUISetOnEvent($GUI_EVENT_CLOSE, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_RESTORE, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_RESIZED, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_DROPPED, "_SysEventHandler", $wMain)

GUISetState(@SW_SHOW, $wMain)

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Main Program Loop ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

While 1
    Sleep(100)
WEnd

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Event Functions ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Func _GUIEventHandler()
    Switch @GUI_CtrlId
        Case $btnMExit
            _TerminateApp()
        Case $btnMOptions
        Case $btnMHelp
    EndSwitch
EndFunc

Func _SysEventHandler()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            If @GUI_WinHandle <> $wMain Then
                _TerminateGUI(@GUI_WinHandle)
            Else
                _TerminateApp()
            EndIf
        Case $GUI_EVENT_MINIMIZE
        Case $GUI_EVENT_RESTORE
        Case $GUI_EVENT_MAXIMIZE
        Case $GUI_EVENT_PRIMARYDOWN
        Case $GUI_EVENT_PRIMARYUP
        Case $GUI_EVENT_SECONDARYDOWN
        Case $GUI_EVENT_SECONDARYUP
        Case $GUI_EVENT_MOUSEMOVE
        Case $GUI_EVENT_RESIZED
        Case $GUI_EVENT_DROPPED
    EndSwitch
EndFunc

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Define Functions ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#region --- Internal Functions
    ;Displays an error message to the user, and optionally times out.
    Func _ErrorMsg($message, $time = 0)
        MsgBox(48 + 262144, "Error!", $message, $time)
    EndFunc

    ;Function to be used to terminate the application. (Clean up Application)
    Func _TerminateApp()
        Exit
    EndFunc
    
    ;This function is to be used with programs that have multiple GUI's and
    ;will optionally terminate application if called incorrectly on the main
    ;GUI.
    Func _TerminateGUI($gui_hWnd, $gui_title = "")
        If $gui_title = "" Then $gui_title = $wTitle
        If $gui_hWnd = $hSome3rdLayerGUI Then
            ;Do 3rd Layer GUI stuff (for example look at RAS-NEW.au3)
            GUIDelete($gui_hWnd)
        Else
            GUIDelete($gui_hWnd)
            If $gui_hWnd = $wMain Then
                _TerminateApp()
            Else
                WinActivate($gui_title)
            EndIf
        EndIf
    EndFunc
#endregion Internal Functions

I hope this further helps you in your understanding of GUI's.

JS

Mental Note to Self: This template has come in quite handy in the last few days.

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

That's simple. Just change $msg to $msg2 in the second script:

$msg2 = GuiGetMsg()
Select
     Case $msg2 = GUI_EVENT_CLOSE
          GuiDelete()
     Case
          ;Else...
EndSelect

I believe this is what you want?

Wow, thanks Dandymcgee. Your peice of code seems to work for everything I have tried it with. This definiatly opens new windows for AutoIt gui programing! AT least for me :lmao: sure others knew this already.

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