Sign in to follow this  
Followers 0
ShadowElf

a button start a new form problem

5 posts in this topic

In first form i have

$bcauta = GUICtrlCreateButton("Cauta", 505, 409, 65, 57)
    GUICtrlSetOnEvent(-1, "cauta")

Then i have function

But when I press the button, it starts a new form created by cauta(), but i lost control of all, i can't exit, i cant't do nothing

How is correct method to do a form, a button who start another form, who fave a button who start another form, etc

Func cauta()
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Opt("GUIOnEventMode", 1)
$Formcauta = GUICreate("Cauta produs", 451, 314, 290, 167)
GUICtrlCreateInput("", 32, 24, 385, 21)
$Listaproduse = GUICtrlCreateList("", 32, 64, 385, 188)
$Button1 = GUICtrlCreateButton("insert", 56, 272, 153, 25)
$Button2 = GUICtrlCreateButton("exit", 232, 273, 153, 25)
GUICtrlSetOnEvent(-1, "cancel")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
EndFunc

Func cancel()
    Exit
EndFunc

I like IT: php, mysql, codeingiter, css, jquery and AUTOIT

Share this post


Link to post
Share on other sites



ShadowElf,

You are mixing OnEvent mode and MessageLoop mode in your script. (At least I read it carefully this time! :) )

I presume you have a Opt("GUIOnEventMode", 1) line at the start of your script because you use GUICtrlSetOnEvent(-1, "cauta") to activate your button. But then in your function you use $nMsg = GUIGetMsg(). If you are in OnEvent mode, GUIGetMsg() will not return any useful values. From the Help file:

"If the GUIOnEventMode option is set to 1 then the return from GUIGetMsg is always 0 and the @error is set to 1"

You need to decide which mode you wish to use and stick with it throughout your script. Note: you can swap from mode to mode, but you need VERY careful coding to get it to work and there is normally no need to do so :) )

I hope that helps,

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

But it not work even in this form

Button exit must close the new form, but not work

Func cauta()
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Opt("GUIOnEventMode", 1)
$Formcauta = GUICreate("Cauta produs", 451, 314, 290, 167)
GUICtrlCreateInput("", 32, 24, 385, 21)
$Listaproduse = GUICtrlCreateList("", 32, 64, 385, 188)
$Button1 = GUICtrlCreateButton("insert", 56, 272, 153, 25)
$Button2 = GUICtrlCreateButton("exit", 232, 273, 153, 25)
GUICtrlSetOnEvent(-1, "cancel")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
WEnd
EndFunc

I like IT: php, mysql, codeingiter, css, jquery and AUTOIT

Share this post


Link to post
Share on other sites

ShadowElf,

You do not need the While...WEnd loop in your function. Just leave the function and return to the loop in your main code. This script gives the idea:

#include <GUIConstantsEx.au3>

Global $Formcauta

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$bcauta = GUICtrlCreateButton("Cauta", 10, 10, 80, 30)
    GUICtrlSetOnEvent(-1, "cauta")

GUISetState()

While 1
    Sleep(10)
WEnd

Func CLOSEClicked()
  Exit
EndFunc

Func cancel()
    GUIDelete($Formcauta)
EndFunc

Func cauta()

$Formcauta = GUICreate("Cauta produs", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "cancel")

$Button2 = GUICtrlCreateButton("exit", 10, 10, 80, 30)
GUICtrlSetOnEvent(-1, "cancel")
GUISetState(@SW_SHOW)

EndFunc

By the way, it is better coding practice to put all the includes at the start of the script, rather than introduce them inside functions. That way all the declarations within the includes are available to the script from the start - it can prevent "not declared" errors. :)

I know Koda inserts them every time - I am afraid you have to move them manually (but as I do not use Koda I cannot be sure of this :) )

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

In first form i have

$bcauta = GUICtrlCreateButton("Cauta", 505, 409, 65, 57)
    GUICtrlSetOnEvent(-1, "cauta")

Then i have function

But when I press the button, it starts a new form created by cauta(), but i lost control of all, i can't exit, i cant't do nothing

How is correct method to do a form, a button who start another form, who fave a button who start another form, etc

Func cauta()
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Opt("GUIOnEventMode", 1)
$Formcauta = GUICreate("Cauta produs", 451, 314, 290, 167)
GUICtrlCreateInput("", 32, 24, 385, 21)
$Listaproduse = GUICtrlCreateList("", 32, 64, 385, 188)
$Button1 = GUICtrlCreateButton("insert", 56, 272, 153, 25)
$Button2 = GUICtrlCreateButton("exit", 232, 273, 153, 25)
GUICtrlSetOnEvent(-1, "cancel")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
EndFunc

Func cancel()
    Exit
EndFunc

I was playing with this sort of thing last night and got this to work. Maybe it will help you. I have not commented script but what I did was start all forms hide them then show them and use their own while loops and re hiding and exiting the loop by changing the flag "$f".

but you should see what is going on with what I did.

REB

#include <ComboConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#include <ButtonConstants.au3>

Dim $Form1_1, $title, $value, $Combo1, $Combo2, $Form1_2, $NewTopic1, $NewTopic2

#Region ### START Koda GUI section ### Form=C:\Users\Dick\Documents\FOLDERS FROM DESKTOP\AUTOIT\AUTOIT FILES\test child windows.kxf

$dummy = GUICreate("test combos", 321, 97) ;, 1081, 91)

$Button1 = GUICtrlCreateButton("combos", 16, 40, 105, 33, $WS_GROUP)

$Button2 = GUICtrlCreateButton("Change Data", 200, 40, 105, 33, $WS_GROUP)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

SetCombos()

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

test1()

test2()

WinActivate($dummy, "")

Case $Button2

SetCombos2()

EndSwitch

WEnd

Func Comment()

$Form1_1 = GUICreate($title, 331, 124) ;, 308, 182, "", "", $dummy)

$Combo1 = GUICtrlCreateCombo(" ", 147, 70, 161, 25)

GUICtrlSetData(-1, $value)

$NewTopic1 = GUICtrlCreateInput("", 142, 14, 161, 21)

$Label1 = GUICtrlCreateLabel("ENTER NEW TOPIC", 32, 16, 105, 17)

$Label2 = GUICtrlCreateLabel("SELECT SAVED TOPIC", 23, 72, 119, 17)

$Label3 = GUICtrlCreateLabel("OR", 64, 40, 30, 24)

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

GUISetState(@SW_HIDE)

EndFunc ;==>Comment

Func Comment2()

$Form1_2 = GUICreate($title, 331, 124) ;, 308, 182, "", "", $dummy)

$Combo2 = GUICtrlCreateCombo(" ", 147, 70, 161, 25)

GUICtrlSetData(-1, $value)

$NewTopic2 = GUICtrlCreateInput("", 142, 14, 161, 21)

$Label1 = GUICtrlCreateLabel("ENTER NEW TOPIC", 32, 16, 105, 17)

$Label2 = GUICtrlCreateLabel("SELECT SAVED TOPIC", 23, 72, 119, 17)

$Label3 = GUICtrlCreateLabel("OR", 64, 40, 30, 24)

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

GUISetState(@SW_HIDE)

EndFunc ;==>Comment2

Func SetCombos()

$x = ""

$value = "1|2|3|4|5"

$title = "MAIN TOPIC ENTRY"

Comment()

$x = ""

$value = "7|8|9|10"

$title = "SUB TOPIC ENTRY"

Comment2()

EndFunc ;==>SetCombos

Func SetCombos2()

$x = ""

$value = "1|2|3|4|5|7|8|9|10"

$title = "NEW MAIN TOPIC ENTRY"

GUICtrlSetData($Combo1, "")

GUICtrlSetData($Combo1, $value)

WinSetTitle("MAIN TOPIC ENTRY", "", $title)

$x = ""

$value = "10|11|12|13|14|15|16|17|18|19|20"

$title = "NEW SUB TOPIC ENTRY"

GUICtrlSetData($Combo2, "")

GUICtrlSetData($Combo2, $value)

EndFunc ;==>SetCombos2

Func test1()

$f = -1

GUISetState(@SW_SHOW, $Form1_1)

While $f < 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $Combo1

$x = GUICtrlRead($Combo1)

GUISetState(@SW_HIDE,$Form1_1)

GUISetState(@SW_HIDE, $dummy)

; DO SOMETHING HERE

MsgBox(0, "", "DOING SOMETHING!", 1)

MsgBox(0, "YOU CHOSE", $x, 1)

GUISetState(@SW_SHOW, $dummy)

$f = 2

Case $NewTopic1

$x = GUICtrlRead($NewTopic1)

GUISetState(@SW_HIDE,$Form1_1)

GUISetState(@SW_HIDE, $dummy)

; DO SOMETHING HERE

MsgBox(0, "", "DOING SOMETHING!", 1)

MsgBox(0, "YOU CHOSE", $x, 1)

GUISetState(@SW_SHOW, $dummy)

$f = 2

EndSwitch

WEnd

EndFunc ;==>test1

Func test2()

$f = -1

GUISetState(@SW_SHOW, $Form1_2)

While $f < 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $Combo2

$x = GUICtrlRead($Combo2)

GUISetState(@SW_HIDE, $Form1_2)

GUISetState(@SW_HIDE, $dummy)

; DO SOMETHING HERE

MsgBox(0, "", "DOING SOMETHING!", 1)

MsgBox(0, "YOU CHOSE", $x, 1)

GUISetState(@SW_SHOW, $dummy)

$f = 2

Case $NewTopic2

$x = GUICtrlRead($NewTopic2)

GUISetState(@SW_HIDE, $Form1_2)

GUISetState(@SW_HIDE, $dummy)

; DO SOMETHING HERE

MsgBox(0, "", "DOING SOMETHING!", 1)

MsgBox(0, "YOU CHOSE", $x, 1)

GUISetState(@SW_SHOW, $dummy)

$f = 2

EndSwitch

WEnd

EndFunc ;==>test2

Edited by reb

MEASURE TWICE - CUT ONCE

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