Jump to content

Recommended Posts

Posted (edited)

hey all, I got 2 similiar functions. when I make a call to one and press ok, window closes. but if i call another one afterwards, first windows stays open until OK is clicked on 2nd window that appears.. code below:

The function puts the selected data on OK button press in clipboard and then closes the window. I copied code from example and removed some lines.. The only bug is stated above :)

Func SM()
Local $menu1, $n1, $n2, $msg, $menustate, $menutext


GUICreate("Employees",250,200) ; will create a dialog box that when displayed is centered

$n1 = GUICtrlCreateList("", 10, 10, 230, 110)
GUICtrlSetData(-1, "2 - Trženje|4 - Produkcija|5 - PE XXX|6 - PE YYY|7 - specific|12 - Servis", "12 - Servis")

$n2 = GUICtrlCreateButton("OK", 10, 120, 50)
GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button
GUISetState() ; will display an empty dialog box

; Run the GUI until the dialog is closed
Do
     $msg = GUIGetMsg()
     If $msg = $n2 Then
$mytxt = GUICtrlRead($n1)
ClipPut(StringRegExpReplace($mytxt, "[^[:digit:]]", ""))
$menutext = GUICtrlRead($menu1, 1) ; return the text of the menu item
EndIf
Until $msg = $n2
EndFunc
Edited by skysel
  • Moderators
Posted

skysel,

As you only ever check for the "OK" button in that GUIGetMsg loop, of course you cannot react to any other events that occur. ;)

I suggest reading the Managing Multiple GUIs tutorial in the Wiki - that shows you how you can watch several GUIs for events. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted

So I've changed the code to this .. on OK press the window now freezes (@SW_DISABLE?)

As I'm not advanced AutoIT user, I'm unsure how to implement code above into the examples of link you provided (in those examples there are 2 windows within 1 function, while I have 1 window per function)..

Func SM()
    Local $menu1, $n1, $n2, $msg, $menutext


    $hGUI1 = GUICreate("Zaposleni - SM",250,200) ; will create a dialog box that when displayed is centered

    $n1 = GUICtrlCreateList("", 10, 10, 230, 110)
    GUICtrlSetData(-1, "2 - Trženje|4 - Produkcija|5 - PE XXX|6 - PE YYY|7 - specific|12 - Servis", "12 - Servis")

    $n2 = GUICtrlCreateButton("OK", 10, 120, 50)
    GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button
    GUISetState() ; will display an empty dialog box

    ; Run the GUI until the dialog is closed

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $n2
                $mytxt = GUICtrlRead($n1)
                ClipPut(StringRegExpReplace($mytxt, "[^[:digit:]]", ""))
                ;$menutext = GUICtrlRead($menu1, 1) ; return the text of the menu item
            GUISetState(@SW_DISABLE,$hGUI1)
    EndSwitch
    WEnd
EndFunc
  • Moderators
Posted

skysel,

on OK press the window now freezes

As you have disabled it with @SW_DISABLE what else would you expect? :huh:

This should give you the idea of how to do it:

#include <GUIConstantsEx.au3>

; Declare these as Global and put placeholder into the control so it does not fire every time you loop
Global $hGUI1, $n2 = 9999

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("Child", 10, 10, 80, 30)

GUISetState()

While 1

    ; Use the Advanced parameter to distinguish between GUIs
    $aMsg = GUIGetMsg(1)
    ; Which GUI
    Switch $aMsg[1]
        Case $hGUI ; Parent
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $cButton
                    SM() ; Run the function
            EndSwitch
        Case $hGUI1 ; Child
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hGUI1)
                    $n2 = 9999
                Case $n2
                    MsgBox(0, "Hi", "Child button pressed")
            EndSwitch
    EndSwitch

WEnd

Func SM()
    ; Do not declare the controls as local - remember they are declared as Global at the top of the script
    Local $menu1, $menutext

    $hGUI1 = GUICreate("Zaposleni - SM",250,200) ; will create a dialog box that when displayed is centered

    $n2 = GUICtrlCreateButton("OK", 10, 120, 50)
    GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button
    GUISetState() ; will display an empty dialog box

    ; Do not run a GUIGetMsg loop here - just return to the main one

EndFunc

Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted (edited)

But what about this piece of code? Should this be in Func(SM)?

And as far as i can see from code, why would i need Case $n2? I have hard time concentrating and thinking today cause of sickness :(

$n1 = GUICtrlCreateList("", 10, 10, 230, 110)
GUICtrlSetData(-1, "2 - Trženje|4 - Produkcija|5 - PE XXX|6 - PE YYY|7 - specific|12 - Servis", "12 - Servis")
Edited by skysel
  • Moderators
Posted

skysel,

I only added those parts of your function which showed how to manage the 2 GUIs - of course you can have as many other controls as you wish, you just add them in the same way as $n2. :)

I have hard time concentrating and thinking today cause of sickness

Then I suggest you wait until you feel better as multiple GUIs need a bit of understanding to get them to work correctly. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted (edited)

Melba23, but that code you gave me invokes 2 GUI objects in my function - which is an undesired result, as my function only needs 1 GUI (guicreate, guictrlcreatelist, guictrlcreatebutton).

I must note, that the code in my first post here is function nr.1, when this function completes it returns a variable to clipboard, which is then specified in whole program as $value5 = ClipGet()

so in the main program i have variables and calls like this:

$value1 = "something"

$value2 = "something2"

$value3 = "something3"

$value4 = "something4"

Function1()

$value5 = ClipGet()

Function2()

$value6 = ClipGet()

I hope this makes some sense now :)

Edited by skysel
  • Moderators
Posted

skysel,

We have obviously been posting at cross purposes. :(

Does this better reflect what you are trying to do? :huh:

#include <GUIConstantsEx.au3>

Function1()
$value5 = ClipGet()
Function1()
$value6 = ClipGet()

MsgBox(0, "Result", $value5 & @CRLF & $value6)

Func Function1()

    $hGUI = GUICreate("Test", 250, 200)
    $cInput = GUICtrlCreateInput("", 10, 10, 200, 20)
    $cButton = GUICtrlCreateButton("To Clip", 10, 50, 80, 30)
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cButton
                $sMyText = GUICtrlRead($cInput)
                If $sMyText <> "" Then
                    ClipPut(StringRegExpReplace($sMyText, "[^[:digit:]]", ""))
                EndIf
                ExitLoop
        EndSwitch
    WEnd

    GUIDelete($hGUI)

EndFunc   ;==>Function1

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted

Yes!

That was the exact thing I wanted to achieve. So below function is finally closing window after selecting an option :-) Many thanks on your help!

Func SM()

    $hGUI = GUICreate("Employees", 250, 200)
    $cInput = GUICtrlCreateList("", 10, 10, 230, 110)
    GUICtrlSetData(-1, "2 - Trženje|4 - Produkcija|5 - PE XXX|6 - PE YYY|7 - specific|12 - Servis", "12 - Servis")
    $cButton = GUICtrlCreateButton("To Clip", 10, 120, 50)
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cButton
                $sMyText = GUICtrlRead($cInput)
                If $sMyText <> "" Then
                    ClipPut(StringRegExpReplace($sMyText, "[^[:digit:]]", ""))
                EndIf
                ExitLoop
        EndSwitch
    WEnd

    GUIDelete($hGUI)

EndFunc
  • Moderators
Posted

skysel,

Glad we got there! :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...