Jump to content

[SOLVED] Return value to running func?


 Share

Recommended Posts

telmob,

I can't follow your code. The following code displays a password dialog as a result of a tray action. If the passwaord is correct it then displays another dialog. This seems to be what you are after. Perhaps you can adapt some of this to your code.

; *** Start added by AutoIt3Wrapper ***
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***



#include <Constants.au3>
#NoTrayIcon

#AutoIt3Wrapper_Add_Constants=n

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)

TrayCreateItem("Config App")
TrayItemSetOnEvent(-1, "Password")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")
TraySetState()

While 1
    Sleep(10000)
WEnd

func Password()

    local $gui010 = guicreate('Password Validation',150,100)
    local $pswd   = GUICtrlCreateInput('Enter Password',10,10,130,20,$es_password)
    local $pbtn   = GUICtrlCreatebutton('Validate Password',10,30,130,20)
    local $status = GUICtrlCreatelabel('',10,90,130,20)
    guisetstate()

    while 1
        switch guigetmsg()
            case $pbtn
                if guictrlread($pswd) = 'password' Then
                    guidelete($gui010)
                    _config()
                    return
                Else
                    GUICtrlSetData($status,'Invalid Password')
                    guictrlsetdata($pswd,'')
                    guictrlsetstate($pswd,$gui_focus)
                endif
            case $gui_event_close
                guidelete($gui010)
                return
        endswitch
    wend

endfunc

func _config()

    local $gui020 = guicreate('Config Dialog')
    guisetstate()

    while 1
        switch guigetmsg()
            Case $gui_event_close
                guidelete($gui020)
                Return
        EndSwitch
    WEnd

endfunc

func _exit()
    ConsoleWrite('Exiting...' & @LF)
    Exit
endfunc

Good Luck,

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

  • Moderators

telmob,

That code is all over the place. How do you expect the password in the input to be checked if you do not show the password GUI so that the user can enter something before checking? :huh:

Try this and see if it works as you require:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIComboBox.au3>
#include <Constants.au3>
#include <GUIListview.au3>
#include <Array.au3>
#include <File.au3>
#include <Crypt.au3>

Opt("WinTitleMatchMode", 2)
Opt("TrayAutoPause", 0)

Opt("TrayIconHide", 0)
Opt("TrayOnEventMode", 1)

TrayMenu("create")
TraySetClick(8)
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "On_DblClick"); ----<-----<-----<-----<-----<-----<-----<-----<----

$FormPasswidth = 280
$FormPassheight = 121
$FormPass = GUICreate("fghjfghjfgj", 280, 121, @DesktopWidth / 2 - $FormPasswidth / 2, @DesktopHeight / 2 - $FormPassheight / 2, BitOR($WS_SYSMENU, $GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
$PassInput = GUICtrlCreateInput("", 8, 29, 257, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
$Butt&#111;nsubmitPass = GUICtrlCreateButton("&OK", 110, 58, 75, 28, $BS_NOTIFY)
$ButtonCancelPass = GUICtrlCreateButton("&Cancel", 191, 58, 75, 28, $BS_NOTIFY)
$EnterPassLabel = GUICtrlCreateLabel("Enter password:", 8, 12, 130, 17, 0)
GUISetState(@SW_HIDE)

$SRPEGUI = GUICreate("App", 200, 200, 500, 500, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE, $GUI_SS_DEFAULT_GUI))
$ButtonLockSystem = GUICtrlCreateButton("Lock System", 54, 80, 91, 28)
GUISetState(@SW_HIDE)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Butt&#111;nsubmitPass
            SubmitPass()
    EndSwitch
WEnd

Func On_DblClick()
    GUISetState(@SW_SHOW, $FormPass)
    If SubmitPass() Then
        MsgBox(0, "Password", "Good")
    Else
        MsgBox(0, "Password", "Bad")
        ;GUISetState(@SW_SHOW, $SRPEGUI)
    EndIf
EndFunc   ;==>On_DblClick

Func SubmitPass(); ----<-----<-----<-----<-----<-----<-----<-----<----
    Local $Pass = 1
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $ButtonCancelPass
                GUISetState(@SW_HIDE, $FormPass)
                Return False
            Case $Butt&#111;nsubmitPass
                Local $PassInputRead = GUICtrlRead($PassInput)
                GUICtrlSetData($PassInput, "")
                GUISetState(@SW_HIDE, $FormPass)
                ExitLoop
        EndSwitch
    WEnd
    If $PassInputRead = $Pass Then
        Return True
    ElseIf $PassInputRead <> $Pass Then
        Return False
    EndIf
EndFunc   ;==>SubmitPass

Func TrayMenu($tAction = "create")
    Opt("TrayMenuMode", 11)
    TrayItemSetOnEvent(-1, "TrayClick")

    $t_settings = TrayCreateItem("Configure")
    TrayItemSetOnEvent(-1, "TrayClick")
    TrayCreateItem("")

    $t_exit = TrayCreateItem("Exit")
    TrayItemSetOnEvent(-1, "TrayClick")

    TraySetState()
EndFunc   ;==>TrayMenu

Func TrayClick()
    $t_msg = TrayItemGetText(@TRAY_ID)
    Select
        Case $t_msg = "Configure"
            Local $state = WinGetState("App", "")
            If WinExists("App", "") Then
                GUISetState(@SW_HIDE, $SRPEGUI)
            ElseIf Not WinExists("App", "") Then
                GUISetState(@SW_SHOW, $SRPEGUI)
            EndIf
        Case $t_msg = "Exit"
            Exit
    EndSelect
EndFunc   ;==>TrayClick

Any better? :)

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

 

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