Sign in to follow this  
Followers 0
Ritch

On press... after click

3 posts in this topic

Region ### START Koda GUI section ### Form=
$GUI = GUICreate("Login", 286, 296, 201, 124)
    GUISetBkColor(0xFFFFFF)
$Group1 = GUICtrlCreateGroup(" Server Info ", 6, 8, 271, 73)
$IP = @IPAddress1
$PORT = 1777
$CON = GUICtrlCreateButton("", 149, 21, 50, 50,$BS_BITMAP) ; Button Connect
 _GUICtrlButton_SetImage($CON,"C:\icones\Login.bmp")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$DIS = GUICtrlCreateButton("", 200, 21, 50, 50,$BS_BITMAP);Button Disconnect
  _GUICtrlButton_SetImage($DIS,"C:\icones\Logout.bmp")
$Group2 = GUICtrlCreateGroup(" Connection Info ", 6, 88, 271, 199)
$SYSMSG = GUICtrlCreateEdit(">Test", 12, 104, 257, 109)
;$SEND_DATA = GUICtrlCreateEdit("", 12, 220, 10, 10)
$SEND_User = GUICtrlCreateInput("User", 85, 225, 90, 18)
GUICtrlCreateLabel("Username:", 22, 225)
GUICtrlCreateLabel("Password:", 22, 256)
$SEND_pass = GUICtrlCreateInput("Senha", 85, 256, 90, 18, $ES_PASSWORD)
$SEND = GUICtrlCreateButton("", 185, 225, 50, 50,$BS_BITMAP)
   _GUICtrlButton_SetImage($SEND,"C:\icones\Locker.bmp")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW,$GUI)

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

$DATA = ""
$read_con = ""
While 1
    $RECV = TCPRecv($SOCKET,512)
    If $RECV <> "" Then
        $TEMP_DATA = GUICtrlRead($SYSMSG)
        GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & "<<" & $RECV)
        _GUICtrlEdit_Scroll($SYSMSG,$SB_SCROLLCARET)
    EndIf
    if $RECV = "Successful login." then
        $check = "1"
    elseif $RECV <> "Successful login." Then
            $RES = 1
        endif
    $MSG = GUIGetMsg()
    Switch $MSG
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CON
            TCPStartup()
            $SOCKET = TCPConnect(@IPAddress1,1777)
            If $SOCKET <> -1 Then
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>Connecting to")
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>Connection...OK")
                  _GUICtrlButton_SetImage($CON,"C:\icones\Logout.bmp")


               Else
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>Unable to connect to")
                _GUICtrlEdit_Scroll($SYSMSG,$SB_SCROLLCARET)
                _GUICtrlButton_SetImage($CON,"C:\icones\Login.bmp")
            EndIf
        Case $DIS
            $RES = TCPCloseSocket($SOCKET)
            If $RES = 1 Then
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>Disconnecting from ")
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>Disconnect...OK")
                _GUICtrlEdit_Scroll($SYSMSG,$SB_SCROLLCARET)
                _GUICtrlButton_SetImage($CON,"C:\icones\Login.bmp")

in this case program show 2 Buttons

one is connect other is Disconnect.

how to creat one button or connect and after press chand action for disconnect.

Share this post


Link to post
Share on other sites



Ritch,

This should give you the idea:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>

$GUI = GUICreate("Login", 286, 296, 201, 124)
GUISetBkColor(0xFFFFFF)

$Group1 = GUICtrlCreateGroup(" Server Info ", 6, 8, 271, 73)

$CON_DIS = GUICtrlCreateButton("Connect", 149, 21, 100, 50, $BS_BITMAP) ; Button Connect
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW, $GUI)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CON_DIS
            _Action()
    EndSwitch

WEnd

Func _Action()
    Switch GUICtrlRead($CON_DIS)
        Case "Connect"
            MsgBox(0, "", "Connected")
            GUICtrlSetData($CON_DIS, "Disconnect")  ; <<<<<<<<<<<<<< change button text
            ; whatever you need as "Connect" code here
        Case "Disconnect"
            MsgBox(0, "", "Disconnected")
            GUICtrlSetData($CON_DIS, "Connect")  ; <<<<<<<<<<<<< change button text
            ; whatever you need as "Disconnect" code here
    EndSwitch
EndFunc   ;==>_Action

M23

P.S. To you and any other readers: Posting COMPLETE code snippets will help enormously if you expect to get an answer. Forcing those who are offer their help here voluntarily to add a number of #include lines and/or other bits and pieces to make the script run is NOT ON! :)


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

#include <GUIConstants.au3>
#Include <GuiEdit.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#include <GuiButton.au3>

Global $SOCKET
Global $SB_SCROLLCARET = 4

#Region ### START Koda GUI section ### Form=
$GUI = GUICreate("Login", 286, 296, 201, 124)
    GUISetBkColor(0xFFFFFF)
$Group1 = GUICtrlCreateGroup(" Server Info ", 6, 8, 271, 73)
$IP = @IPAddress1
$PORT = 1777
$CON = GUICtrlCreateButton("", 149, 21, 50, 50,$BS_BITMAP)
 _GUICtrlButton_SetImage($CON,"C:\icones\Login.bmp")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$DIS = GUICtrlCreateButton("", 149, 21, 50, 50,$BS_BITMAP)
  _GUICtrlButton_SetImage($DIS,"C:\icones\Logout.bmp")
                GUICtrlSetState($DIS, $GUI_DISABLE)
$Group2 = GUICtrlCreateGroup(" Connection Info ", 6, 88, 271, 199)
$SYSMSG = GUICtrlCreateEdit(">Soheelogin Launcher", 12, 104, 257, 109)
;$SEND_DATA = GUICtrlCreateEdit("", 12, 220, 10, 10)
$SEND_User = GUICtrlCreateInput("User", 85, 225, 90, 18)
GUICtrlCreateLabel("Username:", 22, 225)
GUICtrlCreateLabel("Password:", 22, 256)
$SEND_pass = GUICtrlCreateInput("Senha", 85, 256, 90, 18, $ES_PASSWORD)
$SEND = GUICtrlCreateButton("", 185, 225, 50, 50,$BS_BITMAP)
   _GUICtrlButton_SetImage($SEND,"C:\icones\Locker.bmp")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW,$GUI)

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

$DATA = ""
$read_con = ""
While 1
    $RECV = TCPRecv($SOCKET,512)
    If $RECV <> "" Then
        $TEMP_DATA = GUICtrlRead($SYSMSG)
        GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & "<<" & $RECV)
        _GUICtrlEdit_Scroll($SYSMSG,$SB_SCROLLCARET)
    EndIf
    if $RECV = "Successful login." then
        $check = "1"
    elseif $RECV <> "Successful login." Then
            $RES = 1
        endif
    $MSG = GUIGetMsg()
    Switch $MSG
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CON
            TCPStartup()
            $SOCKET = TCPConnect(@IPAddress1,1777)
            If $SOCKET <> -1 Then
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>Connecting to login Server")
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>Connection...OK")

                                GUICtrlSetState($CON, $GUI_DISABLE)
                                GUICtrlSetState($DIS, $GUI_ENABLE)
               Else
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>Unable to connect to login Server")
                _GUICtrlEdit_Scroll($SYSMSG,$SB_SCROLLCARET)
                                GUICtrlSetState($CON, $GUI_ENABLE)
                                GUICtrlSetState($DIS, $GUI_DISABLE)
            EndIf
        Case $DIS
            $RES = TCPCloseSocket($SOCKET)
            If $RES = 1 Then
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>Disconnecting from " & "login Server")
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>Disconnect...OK")
                _GUICtrlEdit_Scroll($SYSMSG,$SB_SCROLLCARET)
                                GUICtrlSetState($CON, $GUI_ENABLE)
                                GUICtrlSetState($DIS, $GUI_DISABLE)

            EndIf
        Case $SEND
            $TEMP_DATA = GUICtrlRead($SYSMSG)
            GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & ">>" & "Login" & GUICtrlRead($SEND_User) & "Enviado...")
            _GUICtrlEdit_Scroll($SYSMSG,$SB_SCROLLCARET)
            IF StringLeft(GUICtrlRead($SEND_User),4) = "GET " Then
                Local $SPLIT = StringSplit(GUICtrlRead($SEND_User)," ")
                Local $HOST = $SPLIT[2]
                Local $PAGE = $SPLIT[3]
                Local $RESULT = _HTTPGet($HOST,$PAGE)
                $TEMP_DATA = GUICtrlRead($SYSMSG)
                GUICtrlSetData($SYSMSG,$TEMP_DATA & @CRLF & "<<" & $RESULT)
                _GUICtrlEdit_Scroll($SYSMSG,$SB_SCROLLCARET)
            Else
            TCPSend($SOCKET,"AUTH" & " " & GUICtrlRead($SEND_User) & " " & GUICtrlRead($SEND_Pass))
            GUICtrlSetData($SEND_User,"")
            EndIf
        Case -3
            Exit 0
    EndSwitch
WEnd

Func _HTTPGet($sHost, $sPage="")
    Local $iSocket = _HTTPConnect($sHost)
    If @error Then Return SetError(1, 0, "")

    Local $sCommand = "GET " & $sPage & " HTTP/1.1" & @CRLF

    $sCommand &= "Host: " & $sHost & @CRLF
    $sCommand &= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0" & @CRLF
    $sCommand &= "Referer: " & $sHost & @CRLF
    $sCommand &= "Connection: close" & @CRLF & @CRLF

    Local $BytesSent = TCPSend($iSocket, $sCommand)
    If $BytesSent = 0 Then Return SetError(2, @error, 0)

    Local $sRecv = "", $sCurrentRecv

    While 1
        $sCurrentRecv = TCPRecv($iSocket, 16)
        If @error <> 0 Then ExitLoop
        If $sCurrentRecv <> "" Then $sRecv &= $sCurrentRecv
    WEnd

    _HTTPShutdown($iSocket)

    Return $sRecv
EndFunc

Func _HTTPConnect($sHost, $iPort=80)
    TCPStartup()

    Local $sName_To_IP = TCPNameToIP($sHost)
    Local $iSocket = TCPConnect($sName_To_IP, $iPort)

    If $iSocket = -1 Then
        TCPCloseSocket($iSocket)
        Return SetError(1, 0, "")
    EndIf

    Return $iSocket
EndFunc

Func _HTTPShutdown($iSocket)
    TCPCloseSocket($iSocket)
    TCPShutdown()
EndFunc

Sorry

here is complete cod.

i use disable/enable in buttons.

=/

in such a way q I made now I function + thus I am with one bug in the hour to change of image. delay and is an gray hole. it could show to me of the form that said as would be?

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