JavaScript_Freek Posted May 24, 2007 Share Posted May 24, 2007 So I try to add my own menu. But it won't work. CHeck to see what's wrong! =D expandcollapse popup;*********************** ; Urbanix (Chat Application) ; Coded by: Black Aye (aka Dan) ; www.mystikfilms.com ; Rawr. ;*********************** #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Global Const $PORT = 31758 Global $list, $sock Global $userlist[17][2] ; [ index ][ username, ctrl id ] Global $defaultstatus = "Ready" Global $status TCPStartUp() $gui = GUICreate("Login", 260, 100) GUICtrlCreateLabel("Server IP", 10, 10, 60, 20) GUICtrlCreateLabel("Username", 10, 40, 60, 20) $ipctrl = GUICtrlCreateEdit(@IPADDRESS1, 80, 10, 170, 20, $ES_READONLY) $userctrl = GUICtrlCreateInput("", 80, 40, 170, 20) $login = GUICtrlCreateButton("Login", 170, 70, 80, 20, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent($login, "_Login") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState() $loop = True While $loop Sleep(20) WEnd $gui = GUICreate("Urbanix - User ("& $user & ")", 460, 320) $list = GUICtrlCreateListView(" Users ", 350, 100, 100, 210) $edit = GUICtrlCreateEdit("Welcome to Urbinix. Follow the rules!" & @CRLF & @CRLF , 10, 160, 330, 150, $ES_READONLY + $WS_VSCROLL + $ES_AUTOVSCROLL) $input = GUICtrlCreateInput("", 10, 100, 330, 20) $send = GUICtrlCreateButton("Send", 10, 130, 80, 20, $BS_DEFPUSHBUTTON) $pm = GUICtrlCreateButton("PM", 100, 130, 80, 20) ; MENU $filemenu = GUICtrlCreateMenu ("&File") $fileitem = GUICtrlCreateMenuitem ("Open",$filemenu) GUICtrlSetState(-1,$GUI_DEFBUTTON) $helpmenu = GUICtrlCreateMenu ("?") $saveitem = GUICtrlCreateMenuitem ("Save",$filemenu) GUICtrlSetState(-1,$GUI_DISABLE) $infoitem = GUICtrlCreateMenuitem ("Info",$helpmenu) $exititem = GUICtrlCreateMenuitem ("Exit",$filemenu) $recentfilesmenu = GUICtrlCreateMenu ("Recent Files",$filemenu,1) $separator1 = GUICtrlCreateMenuitem ("",$filemenu,2) ; create a separator line $viewmenu = GUICtrlCreateMenu("View",-1,1) ; is created before "?" menu $viewstatusitem = GUICtrlCreateMenuitem ("Statusbar",$viewmenu) GUICtrlSetState(-1,$GUI_CHECKED) $okbutton = GUICtrlCreateButton ("OK",50,130,70,20) GUICtrlSetState(-1,$GUI_FOCUS) $cancelbutton = GUICtrlCreateButton ("Cancel",180,130,70,20) $statuslabel = GUICtrlCreateLabel ($defaultstatus,0,165,300,16,BitOr($SS_SIMPLE,$SS_SUNKEN)) ;BANNER GUICtrlCreatePic("giflogo.gif",0,0, 460,85) ;BUTTONS GUICtrlSetOnEvent($send, "_Send") GUICtrlSetOnEvent($pm, "_PM") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUICtrlSetState($input, $GUI_FOCUS) GUISetState() _ReduceMemory() While 1 $msg = GUIGetMsg() If $msg = $fileitem Then $file = FileOpenDialog("Choose file...",@TempDir,"All (*.*)") If @error <> 1 Then GUICtrlCreateMenuitem ($file,$recentfilesmenu) EndIf If $msg = $viewstatusitem Then If BitAnd(GUICtrlRead($viewstatusitem),$GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($viewstatusitem,$GUI_UNCHECKED) GUICtrlSetState($statuslabel,$GUI_HIDE) Else GUICtrlSetState($viewstatusitem,$GUI_CHECKED) GUICtrlSetState($statuslabel,$GUI_SHOW) EndIf EndIf If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $exititem Then ExitLoop If $msg = $infoitem Then Msgbox(0,"Info","Only a test...") Sleep(0) $recv = TCPRecv($sock, 2048) If @error Then mError("Connection lost.", 1) If not $recv Then ContinueLoop ; parse the command(s) $recv = StringSplit($recv, Chr(1)) For $i = 1 to $recv[0] $temp = StringSplit($recv[$i], Chr(2)) Switch $temp[1] Case "rejected" mError("Connection rejected.", 1) Case "kick" mError("Connection kicked.", 1) Case "accepted" If $USER = "admin" Then $kick = GUICtrlCreateButton("Kick", 190, 40, 80, 20) GUICtrlSetOnEvent($kick, "_Kick") EndIf Case "adduser" _AddUser($temp[2]) Case "deluser" _DelUser($temp[2]) Case "exit" mError("Server has closed.", 1) Case Else If $recv[$i] Then GUICtrlSetData($edit, $recv[$i] & @CRLF, 1) EndSwitch Next _ReduceMemory() WEnd Func _Login() $loop = False Global Const $IP = GUICtrlRead($ipctrl) Global Const $USER = GUICtrlRead($userctrl) GUIDelete($gui) If $USER = "admin" Then Local $pass = InputBox("Enter Password:", "Please enter the server password below.", "", "") If @error Then Exit $sock = TCPConnect($IP, $PORT) If $sock = -1 Then mError("Internet needs to be turned on.", 1) Else $sock = TCPConnect($IP, $PORT) If $sock = -1 Then mError("Internet needs to be turned on.", 1) TCPSend($sock, $USER) EndIf EndFunc Func _Send() If not GUICtrlRead($input) Then Return 0 TCPSend($sock, StringReplace(StringReplace(GUICtrlRead($input), Chr(1), ""), Chr(2), "")) GUICtrlSetData($input, "") Return 1 EndFunc Func _PM() If not GUICtrlRead($input) Then Return 0 Local $user = GUICtrlRead($list), $data = StringReplace(StringReplace(GUICtrlRead($input), Chr(1), ""), Chr(2), "") If not $user Then Return 0 $user = GUICtrlRead($user) TCPSend($sock, Chr(1) & "PM" & Chr(2) & $user & Chr(2) & $data) GUICtrlSetData($input, "") GUICtrlSetData($edit, "PM sent to: " & $user & "" & @CRLF & "" & $data & "" & @CRLF, 1) Return 1 EndFunc Func _Kick() Local $user = GUICtrlRead($list) If not $user Then Return 0 $user = GUICtrlRead($user) TCPSend($sock, Chr(1) & "kick" & Chr(2) & $user) GUICtrlSetData($edit, "<** Kick: " & $user & " **>" & @CRLF, 1) Return 1 EndFunc Func _AddUser( $user ) If $user = "admin" and not $userlist[16][0] Then $userlist[16][0] = $user $userlist[16][1] = GUICtrlCreateListViewItem($user, $list) Return 1 EndIf For $i = 0 to 15 If not $userlist[$i][0] Then $userlist[$i][0] = $user $userlist[$i][1] = GUICtrlCreateListViewItem($user, $list) Return 1 EndIf Next Return 0 EndFunc Func _DelUser( $user ) For $i = 0 to 16 If $userlist[$i][0] = $user Then $userlist[$i][0] = "" GUICtrlDelete($userlist[$i][1]) $userlist[$i][1] = 0 Return 1 EndIf Next Return 0 EndFunc Func _ReduceMemory() DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1) EndFunc Func mError( $sText, $iFatal = 0, $sTitle = "Error", $iOpt = 0 ) Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText) If $iFatal Then Exit Return $ret EndFunc Func _RC4( $sData, $sKey ) ; based on code by Valik Local $l[256], $i, $t, $x, $y, $s = "" Local $iLen = StringLen($sKey) For $c = 0 to 255 $l[$c] = $c Next For $c = 0 to 255 $i = Mod(Asc(StringMid($sKey, Mod($c, $iLen) + 1, 1)) + $l[$c] + $i, 256) $t = $l[$c] $l[$c] = $l[$i] $l[$i] = $t Next For $c = 1 to StringLen($sData) $x = Mod($x + 1, 256) $y = Mod($l[$x] + $y, 256) $t = $l[$x] $l[$x] = $l[$y] $l[$y] = $t $s &= Chr(BitXOR(Asc(StringMid($sData, $c, 1)), $l[Mod($l[$x] + $l[$y], 256)])) Next Return $s EndFunc Func _Time() ; based on code by jjohn and his time sync script ; 129.6.15.28 = time-a.nist.gov Local $conn = TCPConnect("129.6.15.28", 37), $recv = "" If $conn = -1 or @error Then Return SetError(1, 0, "...") While $recv = "" $recv = TCPRecv($conn, 512) If @error Then Return SetError(2, 0, "...") WEnd TCPCloseSocket($conn) Return StringTrimRight(Asc(StringMid($recv,1,1))*256^3+Asc(StringMid($recv,2,1))*256^2+Asc(StringMid($recv,3,1))*256+Asc(StringMid($recv,4,1)),1) EndFunc Func _Exit() Exit EndFunc Func OnAutoItExit() TCPSend($sock, Chr(1) & "bye") TCPShutdown() Exit EndFunc [center]Cookyx.com :: Simple LAN Chat[/center] Link to comment Share on other sites More sharing options...
JavaScript_Freek Posted May 25, 2007 Author Share Posted May 25, 2007 anyoone help me? please? [center]Cookyx.com :: Simple LAN Chat[/center] Link to comment Share on other sites More sharing options...
Holger Posted May 27, 2007 Share Posted May 27, 2007 Please read the helpfile again - GUI-section.You cannot mix "GUIGetMsg()" and "GUIOnEventMode"GreetsHolger Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView 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