Jump to content

Instead GUICtrlSetOnEvent


zxtnt09
 Share

Recommended Posts

Hi guys ,

is that any other way to use "GUICtrlSetOnEvent" ? 

something like that : 

Instead GUICtrlSetOnEvent($buttonlogin, "Logout") => 

If GUICtrlRead($buttonlogin = true) Then
GUICtrlSetData($buttonlogin, "Login")
EndIf

* Why i want to change that and i don't like to use that ? 

- because my script does not work good with that , and i want to remove that,
    Opt("GUIOnEventMode", 1)

thanks :)

Edited by zxtnt09
Link to comment
Share on other sites

If I understand you correctly you don't want to use GUIOnEventMode.  If so, you could just poll for events with a loop as below or are you trying to keep the GUIOnEventMode option but change its usage?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 192, 124)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $button; your event you are listening for here
            [do something] ; your code to do something here
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

If I understand you correctly you don't want to use GUIOnEventMode.  If so, you could just poll for events with a loop as below or are you trying to keep the GUIOnEventMode option but change its usage?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 192, 124)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $button; your event you are listening for here
            [do something] ; your code to do something here
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Hi thanks for your helping,

i think your awnser is true and i sooooooooo glad to u.

now i have another problem ! , 

can u please make that for me !!!

it's my code i try to do that but it's imposible :(

#NoTrayIcon

#Region AutoIt3Wrapper directives section
;~ #Autoit3Wrapper_Testing=Y;=> Change to N when compile
#AutoIt3Wrapper_Icon=E:\wamp\www\favicon.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=Y
;~ #AutoIt3Wrapper_Compile_both=Y;=> Compile both X86 and X64 in one run
#AutoIt3Wrapper_Res_Comment=Developed by Juno_okyo
#AutoIt3Wrapper_Res_Description=Developed by Juno_okyo
#AutoIt3Wrapper_Res_Fileversion=1.0.0.10
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=Y
#AutoIt3Wrapper_Res_ProductVersion=1.0.0.0;=>Edit
#AutoIt3Wrapper_Res_LegalCopyright=(C) 2015 Juno_okyo. All rights reserved.
#EndRegion AutoIt3Wrapper directives section

#Region Includes
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiListView.au3>
#include <GuiTab.au3>
#include <Array.au3>
#include <Misc.au3>
#include 'includes/BinaryCall.au3'
#include 'includes/JSON.au3'
#include 'includes/http.au3'
#EndRegion Includes

;~ _Singleton(@ScriptName)

#Region Options
Opt('MustDeclareVars', 1)
Opt('WinTitleMatchMode', 2)
Opt('GUICloseOnESC', 0)
Opt('GUIOnEventMode', 1)
Opt('TrayOnEventMode', 1)
#EndRegion Options

; Script Start - Add your code below here
Global Const $DEBUG_MODE = False ; Please change value to False when compile

Global Const $SERVER = 'http://test.com/autoit/index.php?act='
Global Const $ENDPOINT_LOGIN = $SERVER & 'login'
Global Const $ENDPOINT_LOGOUT = $SERVER & 'logout'
Global Const $ENDPOINT_CREATE = $SERVER & 'create'
Global Const $ENDPOINT_UPDATE = $SERVER & 'update'
Global Const $ENDPOINT_READ = $SERVER & 'read'
Global Const $ENDPOINT_DELETE = $SERVER & 'delete'

#Region ### START Koda GUI section ### Form=E:\Program Files\AutoIt3\Code\_TUTORIAL\MainForm.kxf
Global $MainForm = GUICreate('[Tutorial] AutoIt - PHP - MySQL by Juno_okyo', 410, 445)
GUISetFont(12, 400, 0, 'Arial')
GUISetOnEvent($GUI_EVENT_CLOSE, 'MainFormClose')
Global $GroupLogin = GUICtrlCreateGroup('Member Login', 10, 8, 390, 115)
Global $LabelUsername = GUICtrlCreateLabel('Username:', 20, 40, 80, 22)
Global $InputUsername = GUICtrlCreateInput('', 105, 38, 162, 26, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
Global $LabelPassword = GUICtrlCreateLabel('Password:', 20, 80, 78, 22)
Global $InputPassword = GUICtrlCreateInput('', 105, 78, 162, 26, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_PASSWORD))
Global $ButtonLogin = GUICtrlCreateButton('Login', 278, 38, 110, 67)
GUICtrlSetFont(-1, 20, 400, 0, 'Arial')
GUICtrlSetCursor(-1, 0)
GUICtrlSetOnEvent(-1, 'ButtonLoginClick')
GUICtrlSetState(-1, $GUI_DEFBUTTON)
GUICtrlCreateGroup('', -99, -99, 1, 1)
Global $MainTab = GUICtrlCreateTab(10, 133, 390, 280)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
GUICtrlSetOnEvent(-1, 'MainTabChange')
Global $TabCreate = GUICtrlCreateTabItem('Create or Update')
Global $LabelUsername2 = GUICtrlCreateLabel('Username:', 19, 169, 80, 22)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $InputUsername2 = GUICtrlCreateInput('', 109, 167, 278, 26, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
GUICtrlSetLimit(-1, 15)
Global $LabelPassword2 = GUICtrlCreateLabel('Password:', 19, 209, 78, 22)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $InputPassword2 = GUICtrlCreateInput('', 109, 207, 278, 26, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $LabelEmail = GUICtrlCreateLabel('Email:', 19, 249, 48, 22)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $InputEmail = GUICtrlCreateInput('', 109, 247, 278, 26, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
GUICtrlSetOnEvent(-1, 'InputEmailChange')
GUICtrlSetLimit(-1, 100)
Global $LabelGender = GUICtrlCreateLabel('Gender:', 19, 289, 60, 22)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $ComboGender = GUICtrlCreateCombo('', 109, 287, 278, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, '|Male|Female')
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $LabelGroup = GUICtrlCreateLabel('Group:', 19, 329, 51, 22)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $ComboGroup = GUICtrlCreateCombo('', 109, 327, 278, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, 'Member|Admin', 'Member')
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $ButtonCreate = GUICtrlCreateButton('Create', 109, 367, 72, 30)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
GUICtrlSetCursor(-1, 0)
GUICtrlSetOnEvent(-1, 'ButtonCreateClick')
Global $ButtonReset = GUICtrlCreateButton('Reset', 297, 367, 90, 30)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
GUICtrlSetCursor(-1, 0)
GUICtrlSetOnEvent(-1, 'ButtonResetClick')
Global $ButtonUpdate = GUICtrlCreateButton('Update', 191, 367, 96, 30)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
GUICtrlSetCursor(-1, 0)
GUICtrlSetOnEvent(-1, 'ButtonUpdateClick')
Global $TabRead = GUICtrlCreateTabItem('Read')
Global $LabelSearch = GUICtrlCreateLabel('Username:', 19, 169, 80, 22)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $InputSearch = GUICtrlCreateInput('', 109, 167, 160, 26, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
GUICtrlSetLimit(-1, 15)
Global $ButtonSearch = GUICtrlCreateButton('Search', 281, 167, 108, 25)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
GUICtrlSetCursor(-1, 0)
GUICtrlSetOnEvent(-1, 'ButtonSearchClick')
Global $ListViewRead = GUICtrlCreateListView('Item|Value', 19, 206, 371, 196, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_AUTOARRANGE), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_FULLROWSELECT))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 250)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $TabDelete = GUICtrlCreateTabItem('Delete')
Global $LabelFilter = GUICtrlCreateLabel('Filter:', 19, 169, 43, 22)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $ComboFilter = GUICtrlCreateCombo('', 94, 167, 290, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, 'User ID|Username|Email', 'Username')
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
GUICtrlSetOnEvent(-1, 'ComboFilterChange')
Global $LabelValue = GUICtrlCreateLabel('Value:', 19, 209, 48, 22)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $InputValue = GUICtrlCreateInput('', 94, 207, 290, 26, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER))
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
Global $ButtonDelete = GUICtrlCreateButton('Delete user?', 94, 247, 290, 30)
GUICtrlSetFont(-1, 12, 400, 0, 'Arial')
GUICtrlSetCursor(-1, 0)
GUICtrlSetOnEvent(-1, 'ButtonDeleteClick')
GUICtrlCreateTabItem('')
GUICtrlCreateStatusBar($MainForm, 260)

If Not $DEBUG_MODE Then toggleControl(0)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func ButtonCreateClick()
    _user('create')
EndFunc   ;==>ButtonCreateClick

Func ButtonUpdateClick()
    _user('update')
EndFunc   ;==>ButtonUpdateClick

Func _user($type = 'create')
    If Not _validateInput($type) Then
        _showError('Please make sure you enter correct user info!', $InputUsername2)
        Return False
    EndIf

    Local $endpoint = ($type = 'create') ? $ENDPOINT_CREATE : $ENDPOINT_UPDATE

    Local $data = 'username=' & urlEncode(GUICtrlRead($InputUsername2)) & _
            '&password=' & urlEncode(GUICtrlRead($InputPassword2)) & _
            '&email=' & urlEncode(GUICtrlRead($InputEmail)) & _
            '&gender=' & urlEncode(GUICtrlRead($ComboGender)) & _
            '&group=' & urlEncode(GUICtrlRead($ComboGroup))

    If $DEBUG_MODE Then
        MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '$data' & @CRLF & @CRLF & 'Return:' & @CRLF & $data) ;### Debug MSGBOX
    EndIf

    Local $request = _httpRequest($endpoint, 'POST', $data)
    Local $json = Json_Decode($request[2])
    Local $success = Json_Get($json, '["success"]')

    If $DEBUG_MODE Then _ArrayDisplay($request)

    If $success Then
        Local $msg
        If $type = 'create' Then
            $msg = 'New user has been created!'
        Else
            $msg = GUICtrlRead($InputUsername2) & "'s info has been updated!"
        EndIf

        MsgBox(64 + 262144, 'Message', $msg, 0, $MainForm)
        Return True
    Else
        Local $error
        If $type = 'create' Then
            $error = 'Cannot to create new user. Please try again!'
        Else
            $error = 'Cannot to update user: ' & GUICtrlRead($InputUsername2)
        EndIf

        _showError($error)
        Return False
    EndIf
EndFunc   ;==>_user

Func ButtonDeleteClick()
    Local $filter, $value
    $filter = StringLower(GUICtrlRead($ComboFilter))
    $value = GUICtrlRead($InputValue)

    If Not $value Then
        _showError('Please enter a value!', $InputValue)
        Return False
    EndIf

    ; Validate input value
    Select
        Case $filter = 'user id'
            If Not StringRegExp($value, '\d+') Then
                _showError('You must to enter a number!', $InputValue)
                Return False
            EndIf

            ; Change to "id" column in database
            $filter = 'id'

        Case $filter = 'email'
            If Not isEmail($value) Then
                _showError('You must to enter an email!', $InputValue)
                Return False
            EndIf
    EndSelect

    ; Confirmation
    If Not $DEBUG_MODE Then
        If MsgBox(32 + 4 + 256 + 262144, 'Confirm', 'Are you sure to delete this user?', 0, $MainForm) = 7 Then Return False
    EndIf

    Local $data = 'filter=' & urlEncode($filter) & _
            '&value=' & urlEncode($value)

    Local $request = _httpRequest($ENDPOINT_DELETE, 'POST', $data)
    Local $json = Json_Decode($request[2])
    Local $success = Json_Get($json, '["success"]')

    If $DEBUG_MODE Then _ArrayDisplay($request)

    If $success Then
        MsgBox(64 + 262144, 'Message', 'This user was deleted from Database!', 0, $MainForm)
        GUICtrlSetData($InputValue, '') ; Reset input
        GUICtrlSetState($InputValue, $GUI_FOCUS)
        Return True
    Else
        _showError('Cannot delete this user. Please try again!')
        Return False
    EndIf
EndFunc   ;==>ButtonDeleteClick

Func ButtonLoginClick()
    Local $username, $password

    $username = GUICtrlRead($InputUsername)
    If Not $username Then
        _showError('Please enter your username!', $InputUsername)
        Return False
    EndIf

    $password = GUICtrlRead($InputPassword)
    If Not $password Then
        _showError('Please enter your password!', $InputPassword)
        Return False
    EndIf

    ; Disable controls
    GUICtrlSetState($InputUsername, $GUI_DISABLE)
    GUICtrlSetState($InputPassword, $GUI_DISABLE)
    GUICtrlSetState($ButtonLogin, $GUI_DISABLE)

    ; Make login request to server
    Local $data, $request
    $data = 'username=' & urlEncode($username)
    $data &= '&password=' & urlEncode($password)

    $request = _httpRequest($ENDPOINT_LOGIN, 'POST', $data)

    If $DEBUG_MODE Then _ArrayDisplay($request)

    Local $json = Json_Decode($request[2])
    Local $success = Json_Get($json, '["success"]')

    ; Enable controls
    GUICtrlSetState($InputUsername, $GUI_ENABLE)
    GUICtrlSetState($InputPassword, $GUI_ENABLE)
    GUICtrlSetState($ButtonLogin, $GUI_ENABLE)

    If $success Then
        ; Login success
        GUICtrlSetState($InputUsername, $GUI_DISABLE)
        GUICtrlSetState($InputPassword, $GUI_DISABLE)

        ; Switch to logout button
        GUICtrlSetData($ButtonLogin, 'Logout')
        GUICtrlSetOnEvent($ButtonLogin, 'Logout')

        ; Focus to input in first tab
        GUICtrlSetState($InputUsername2, $GUI_FOCUS)

        ; Enable all controls
        toggleControl(1)
        Return True
    Else
        Local $errorCode = Json_Get($json, '["data"]')
        If $errorCode = -1 Then
            _showError('Your username or password is incorrect!', $InputUsername)
            Return False
        Else
            _showError('You have already logged in at other device. Please logout first!')
            Return False
        EndIf
    EndIf
EndFunc   ;==>ButtonLoginClick

Func ButtonResetClick()
    GUICtrlSetData($InputUsername2, '')
    GUICtrlSetData($InputPassword2, '')
    GUICtrlSetData($InputEmail, '')

    ; Focus to first input
    GUICtrlSetState($InputUsername2, $GUI_FOCUS)
EndFunc   ;==>ButtonResetClick

Func ButtonSearchClick()
    Local $keyword = GUICtrlRead($InputSearch)
    If Not $keyword Then
        _showError('Please enter a keyword!', $InputSearch)
        Return False
    EndIf

    GUICtrlSetState($InputSearch, $GUI_DISABLE)
    GUICtrlSetState($ButtonSearch, $GUI_DISABLE)

    ; Reset listview
    _GUICtrlListView_DeleteAllItems($ListViewRead)

    Local $data = 'username=' & urlEncode($keyword)
    Local $request = _httpRequest($ENDPOINT_READ, 'POST', $data)
    Local $json = Json_Decode($request[2])
    Local $success = Json_Get($json, '["success"]')

;~  If $DEBUG_MODE Then _ArrayDisplay($request)

    GUICtrlSetState($InputSearch, $GUI_ENABLE)
    GUICtrlSetState($ButtonSearch, $GUI_ENABLE)

    If $success Then
        ; Add data to list view
        Local $status = (Json_Get($json, '["data"]["is_online"]') = 1) ? 'Online' : 'Offline'

        _GUICtrlListView_BeginUpdate($ListViewRead)

        ; Item column (label)
        _GUICtrlListView_AddItem($ListViewRead, 'User ID')
        _GUICtrlListView_AddItem($ListViewRead, 'Username')
        _GUICtrlListView_AddItem($ListViewRead, 'Password')
        _GUICtrlListView_AddItem($ListViewRead, 'Email')
        _GUICtrlListView_AddItem($ListViewRead, 'Gender')
        _GUICtrlListView_AddItem($ListViewRead, 'Group')
        _GUICtrlListView_AddItem($ListViewRead, 'IP Address')
        _GUICtrlListView_AddItem($ListViewRead, 'Status')

        ; Value column
        _GUICtrlListView_AddSubItem($ListViewRead, 0, Json_Get($json, '["data"]["id"]'), 1)
        _GUICtrlListView_AddSubItem($ListViewRead, 1, Json_Get($json, '["data"]["username"]'), 1)
        _GUICtrlListView_AddSubItem($ListViewRead, 2, Json_Get($json, '["data"]["password"]'), 1)
        _GUICtrlListView_AddSubItem($ListViewRead, 3, Json_Get($json, '["data"]["email"]'), 1)
        _GUICtrlListView_AddSubItem($ListViewRead, 4, _ucfirst(Json_Get($json, '["data"]["gender"]')), 1)
        _GUICtrlListView_AddSubItem($ListViewRead, 5, _ucfirst(Json_Get($json, '["data"]["group"]')), 1)
        _GUICtrlListView_AddSubItem($ListViewRead, 6, Json_Get($json, '["data"]["ip_address"]'), 1) ; IP Address
        _GUICtrlListView_AddSubItem($ListViewRead, 7, $status, 1) ; Status

        _GUICtrlListView_EndUpdate($ListViewRead)

        Return True
    Else
        _showError('Cannot to find user: ' & $keyword, $InputSearch)
        Return False
    EndIf
EndFunc   ;==>ButtonSearchClick

Func ComboFilterChange()
    GUICtrlSetState($InputValue, $GUI_FOCUS)
EndFunc   ;==>ComboFilterChange

Func InputEmailChange()
    ; Validate email address
    Local $email = GUICtrlRead($InputEmail)
    If $email Then
        If Not isEmail($email) Then
            _showError('Your email address is invalid!', $InputEmail)
            Return False
        EndIf
    EndIf
EndFunc   ;==>InputEmailChange

Func isEmail($str)
    Return StringRegExp($str, '\b[\D\d._%+-]+@[\D\d.-]+\.[\D]{2,6}\b')
EndFunc   ;==>isEmail

Func MainTabChange()
    Local $tabId = _GUICtrlTab_GetCurFocus($MainTab)
    Local $ctrlId = $InputUsername2 ; First tab by default

    ; Focus to first input control on each tab
    Select
        Case $tabId = 0
            $ctrlId = $InputUsername2

        Case $tabId = 1
            $ctrlId = $InputSearch

        Case Else
            $ctrlId = $InputValue
    EndSelect

    GUICtrlSetState($ctrlId, $GUI_FOCUS)
EndFunc   ;==>MainTabChange

Func _showError($errorMsg, $ctrId = Default)
    MsgBox(16 + 262144, 'Error', $errorMsg, 0, $MainForm)

    If $ctrId <> Default Then GUICtrlSetState($ctrId, $GUI_FOCUS)
EndFunc   ;==>_showError

Func _validateInput($type = 'create')
    Local $username, $password, $email, $gender
    $username = GUICtrlRead($InputUsername2)
    $password = GUICtrlRead($InputPassword2)
    $email = GUICtrlRead($InputEmail)
    $gender = GUICtrlRead($ComboGender)

;~  If $type = 'create' Then
    Return ($username And $password And isEmail($email) And $gender <> '')
;~  Else
;~      If Not $username Then Return False
;~      If Not $password Or Not $email Or $gender = '' Then Return False

;~      If $email Then
;~          If Not isEmail($email) Then Return False
;~      EndIf
;~  EndIf
EndFunc   ;==>_validateInput

Func Logout()
    If Not $DEBUG_MODE Then
        ; Confirmation
        If MsgBox(32 + 4 + 256 + 262144, 'Confirm', 'Are you sure to logout?', 0, $MainForm) = 7 Then Return False
    EndIf

    Local $username, $data, $request
    $username = GUICtrlRead($InputUsername)
    $data = 'username=' & urlEncode($username)
    $request = _httpRequest($ENDPOINT_LOGOUT, 'POST', $data)
    Local $json = Json_Decode($request[2])
    Local $success = Json_Get($json, '["success"]')

    If $DEBUG_MODE Then _ArrayDisplay($request)

    If $success Then
        ; Reset input controls
        GUICtrlSetData($InputUsername, '')
        GUICtrlSetData($InputPassword, '')
        GUICtrlSetState($InputUsername, $GUI_ENABLE)
        GUICtrlSetState($InputPassword, $GUI_ENABLE)

        ; Switch to login button
        GUICtrlSetData($ButtonLogin, 'Login')
        GUICtrlSetOnEvent($ButtonLogin, 'ButtonLoginClick')

        ; Focus to username input
        GUICtrlSetState($InputUsername, $GUI_FOCUS)

        ; Disable all controls
        If Not $DEBUG_MODE Then toggleControl(0)
        Return True
    Else
        _showError('Cannot to logout. Please try again!')
        Return False
    EndIf
EndFunc   ;==>Logout

Func toggleControl($state = 1)
    $state = ($state = 1) ? 64 : 128 ; 64=Enable; 128=Disable
    GUICtrlSetState($InputUsername2, $state)
    GUICtrlSetState($InputPassword2, $state)
    GUICtrlSetState($InputEmail, $state)
    GUICtrlSetState($InputSearch, $state)
    GUICtrlSetState($InputValue, $state)
    GUICtrlSetState($ComboGender, $state)
    GUICtrlSetState($ComboGroup, $state)
    GUICtrlSetState($ComboFilter, $state)
    GUICtrlSetState($ButtonCreate, $state)
    GUICtrlSetState($ButtonUpdate, $state)
    GUICtrlSetState($ButtonReset, $state)
    GUICtrlSetState($ButtonSearch, $state)
    GUICtrlSetState($ButtonDelete, $state)
    GUICtrlSetState($ListViewRead, $state)
EndFunc   ;==>toggleControl

Func _ucfirst($str)
    Return StringUpper(StringMid($str, 1, 1)) & StringMid($str, 2)
EndFunc   ;==>_ucfirst

Func GUICtrlCreateStatusBar($gui, $space = 280, $text = 'Developed by Juno_okyo', $copyright = 'J2TeaM')
    Local $statusBar = _GUICtrlStatusBar_Create($gui)
    Local $statusBar_PartsWidth[2] = [$space, -1]
    _GUICtrlStatusBar_SetParts($statusBar, $statusBar_PartsWidth)
    _GUICtrlStatusBar_SetText($statusBar, $text, 0)
    _GUICtrlStatusBar_SetText($statusBar, 'Copyright ' & Chr(169) & ' ' & @YEAR & ' ' & $copyright, 1)
    _GUICtrlStatusBar_SetMinHeight($statusBar, 3)
    Return $statusBar
EndFunc   ;==>GUICtrlCreateStatusBar

Func MainFormClose()
    ; Make sure user is logged out
    If GUICtrlRead($ButtonLogin) = 'logout' Then
        _showError('Please logout your accout first!')
        Return False
    EndIf

    Exit
EndFunc   ;==>MainFormClose

Code from : https://www.autoitscript.com/forum/topic/173984-the-combination-of-autoit-php-and-mysql/

GUICtrlSetOnEvent is in this lines :

Line Number : 42 , 69 , 74 , 89 , 104 , 108 , 112 , 122 , 133 , 141 , 306 , 480

Red : Important

Green : Not Important

======================================================================

Or if you have good idea to connect my program to mysql by easy way ( without OnEvent ) i'm so glad to listen that 

Thanks and sorry for my bad english <3

Edited by zxtnt09
Red - Green / Or
Link to comment
Share on other sites

Hmmm.  I think you are asking how to convert the button listeners from GuiCtrlSetOnEvent to a listener used in the while loop.  If you look at my earlier post it does that.
 You would delete Opt("GUIOnEventMode", 1).  Then in the while loop a button click would look like this:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $ButtonLogin; will fire when this button with this name is pressed
            logout() ; will do this when the button is pressed
                     ; will do everything after "Case" and before the next case
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

I did not read all the code to figure out when you call login() vs. logout() based on pressing the $ButtonLogin button - but hopefully you can take it from here. :D

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

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