Ritch Posted October 18, 2009 Share Posted October 18, 2009 expandcollapse popupRegion ### 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 18, 2009 Moderators Share Posted October 18, 2009 Ritch,This should give you the idea:expandcollapse popup#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 ;==>_ActionM23P.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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Ritch Posted October 18, 2009 Author Share Posted October 18, 2009 expandcollapse popup#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? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now