JavaScript_Freek Posted February 4, 2009 Posted February 4, 2009 (edited) When you type a short message such as "hi" then type "hi" again, you will see that there is no line break. For example load the .au3 below ... make your username a short one and send a short message... How do I add a line break after someone "speaks". expandcollapse popup#include<Array.au3> #include<GuiListView.au3> #include<Misc.au3> #include<GUIConstantsEx.au3> #include<ListViewConstants.au3> #include<WindowsConstants.au3> #include<StructureConstants.au3> #include <ButtonConstants.au3> #include <Sound.au3> Opt("GUIOnEventMode", 1) #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=chat.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Global $contactserver, $buddy, $contactdata, $msgdata, $sel, $rename, $menu1, $ms_ Global $hlistview, $c_list, $chat_gui, $buttoncontext, $buttonitem, $msg, $me Dim $buddy[1] Dim $inifile = @MyDocumentsDir & "\chat.ini" load() Global $me $chat_gui = GUICreate("LAN Chat v1.2", 512, 390, 526, 146, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_ACCEPTFILES, $WS_EX_TOPMOST)) GUICtrlCreateLabel("Who's online?", 325, 7, 100) $c_list = GUICtrlCreateListView("", 325, 28, 183, 347, $LVS_LIST, $WS_EX_CLIENTEDGE) _GUICtrlListView_SetColumnWidth($c_list, 0, 100) _GUICtrlListView_SetExtendedListViewStyle($c_list, $LVS_EX_FULLROWSELECT) _GUICtrlListView_SetView($c_list, 3) _GUICtrlListView_AddItem($c_list, $me) $input = GUICtrlCreateInput("Welcome " & $me, 8, 350, 250, 25) $Button1 = GUICtrlCreateButton("send", 263, 350, 54, 25, 0) GUICtrlSetOnEvent(-1, "sendit") $hlistview = GUICtrlCreateListView("", 8, 28, 306, 315, $LVS_LIST, $WS_EX_CLIENTEDGE) _GUICtrlListView_AddItem($hlistview, $me & " has signed on.") _GUICtrlListView_SetColumnWidth($hlistview, 0, 100) _GUICtrlListView_SetExtendedListViewStyle($hlistview, $LVS_EX_FULLROWSELECT) _GUICtrlListView_SetView($hlistview, 3) GUISetOnEvent($GUI_EVENT_CLOSE, "quit") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() $me = "" load() If $me = "" Then $me = InputBox("Who Are you", "Your name", "") Global $me IniWrite($inifile, "me", 0, $me) _GUICtrlListView_AddItem($c_list, $me) _ArrayAdd($buddy, $me) Endif $PrivateIP = @IPAddress1 ; Start The UDP Services ;============================================== UDPStartup() ; Bind to a SOCKET ;============================================== $contactserver = UDPBind($PrivateIP, 65335) Sleep(1000) ;create multicast address $splitaddress = StringSplit($PrivateIP, ".") $changeaddress = $splitaddress[1] & "." & $splitaddress[2] & "." & $splitaddress[3] & "." & "255" ;send packet $contactcast = UDPOpen($changeaddress, 65335) AdlibEnable("check", 1000) While 1 $contactdata = UDPRecv($contactserver, 50) If StringInStr($contactdata, "|") > 0 Then $str = StringSplit($contactdata, "|") If $contactdata <> "" And StringInStr($str[1], ".") = 4 And StringInStr($str[1], ".", 0, 2) = 8 Then $ar = _ArraySearch($buddy, $str[2]) If @error Then ConsoleWrite("Adding via Buddy") _ArrayAdd($buddy, $str[2]) _GUICtrlListView_AddItem($c_list, $str[2]) Else $c = _GUICtrlListView_GetItemText($c_list, $ar - 1) If StringInStr($c, "On-line") = 0 Then _GUICtrlListView_SetItemText($c_list, $ar - 1, $str[2] & " On-line") If $str[2] <> $me Then _GUICtrlListView_AddItem($hlistview, $str[2] & " has signed on") _SoundPlay("C:\Windows\Media\Speech on.wav",0) EndIf EndIf EndIf EndIf If $contactdata <> "" Then $tmp = StringSplit($contactdata, "|") $msgdata = $tmp[2] If StringInStr($msgdata, $me) = 0 And StringInStr($tmp[1], ".") <> 4 And StringInStr($tmp[2], "Has signed") = 0 Then $str = StringSplit($msgdata, "|") $last = $str[0] _SoundPlay("Windows Shutdown.wav", 0) _GUICtrlListView_AddItem($hlistview, $str[$last] & " says: " & $tmp[1]) _GUICtrlListView_Scroll($hlistview, 0, 50) ElseIf StringInStr($msgdata, $me) = 0 And StringInStr($tmp[1], ".") <> 4 And StringInStr($tmp[2], "Has signed") > 0 Then $str = StringSplit($msgdata, "|") $last = $str[0] If StringInStr($tmp[2], "Has signed off") > 0 Then _GUICtrlListView_AddItem($hlistview, $tmp[1] & " " & $str[$last]) _GUICtrlListView_Scroll($hlistview, 0, 50) $ar = _ArraySearch($buddy, $tmp[1]) _GUICtrlListView_SetItemText($c_list, $ar - 1, $tmp[1] & " Off-line") EndIf EndIf EndIf If _IsPressed("OD") Then sendit() Sleep(50) WEnd Func check() If $me <> "" Then UDPSend($contactcast, @IPAddress1 & "|" & $me) EndFunc ;==>check Func quit() _GUICtrlListView_AddItem($hlistview, $me & " has signed off.") _GUICtrlListView_DeleteItem($c_list, $me) _SoundPlay("C:\Windows\Media\Speech Off.wav",0) AdlibDisable() Sleep(1000) UDPSend($contactcast, $me & "|Has signed off") UDPCloseSocket($PrivateIP) UDPShutdown() For $i = 1 To UBound($buddy) - 1 IniWrite($inifile, "contacts", $i - 1, $buddy[$i]) Next Exit EndFunc ;==>quit Func load() $me = IniRead($inifile, "me", 0, "") $var = IniReadSection($inifile, "contacts") If Not @error Then For $x = 1 To $var[0][0] If $var[$x][1] <> @IPAddress1 Then _GUICtrlListView_AddItem($c_list, $var[$x][1] & " Off-line") _ArrayAdd($buddy, $var[$x][1]) Else If $me <> "" Then _GUICtrlListView_AddItem($c_list, $me & " Off-line") _ArrayAdd($buddy, $me) EndIf EndIf Next EndIf EndFunc ;==>load Func sendit() ConsoleWrite("SEND" & @LF) UDPSend($contactcast, GUICtrlRead($input) & "|" & $me) _GUICtrlListView_AddItem($hlistview, $me & " speaks: " & GUICtrlRead($input)) _GUICtrlListView_AddItem($hlistview,"") GUICtrlSetData($input, "") _GUICtrlListView_Scroll($hlistview, 0, 150) EndFunc ;==>sendit Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR, $iCode, $tInfo, $iItem $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $iCode = DllStructGetData($tNMHDR, "Code") Switch $iCode Case $NM_RCLICK $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $sel = DllStructGetData($tInfo, "Index") ConsoleWrite("Right click") Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) If $iItem = _GUICtrlListView_GetColumnCount($hListView) - 1 Then Return 1 ConsoleWrite("double click") EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func rename() ConsoleWrite("func rename") EndFunc ;==>rename Edited February 4, 2009 by JavaScript_Freek [center]Cookyx.com :: Simple LAN Chat[/center]
jvanegmond Posted February 4, 2009 Posted February 4, 2009 (edited) Your original post makes no sense, because it doesn't let us reproduce the issue. Please just isolate the issue in your script, write an example how to reproduce, and then post ... Edited February 4, 2009 by Manadar github.com/jvanegmond
yucatan Posted February 4, 2009 Posted February 4, 2009 Your original post makes no sense, because it doesn't let us reproduce the issue. Please just isolate the issue in your script, write an example how to reproduce, and then post ...to get a break in a $var or in your case a syntax use @CRLF
JavaScript_Freek Posted February 4, 2009 Author Posted February 4, 2009 (edited) Thank you yucatan. :-) But where it says "speaks". Where I put it after the the input... it does not work. Such as Func sendit() UDPSend($contactcast, GUICtrlRead($input) & "|" & $me) _GUICtrlListView_AddItem($hlistview, $me & " speaks: " & GUICtrlRead($input) & @CRLF) _GUICtrlListView_AddItem($hlistview,"") GUICtrlSetData($input, "") _GUICtrlListView_Scroll($hlistview, 0, 150) EndFunc ;==>sendit Edited February 4, 2009 by JavaScript_Freek [center]Cookyx.com :: Simple LAN Chat[/center]
JavaScript_Freek Posted February 7, 2009 Author Posted February 7, 2009 Any feedback on this? [center]Cookyx.com :: Simple LAN Chat[/center]
CodyBarrett Posted February 7, 2009 Posted February 7, 2009 do you want it to go some thing like this User Says : hi in this case put the @CRLF between the name and the stuff you want to send like this (TCP) not (UDP) for $i = 0 to 100; How Many You Want To Send To tcpsend($Socket[$i],$name & ' Says :'& @CRLF & Guictrlread($Send)) next or what do you want? [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size]
JavaScript_Freek Posted February 7, 2009 Author Posted February 7, 2009 User says: Hihihi User2 says: hi! Because when I do this... it's like: User says: Hihihi User2 says: hi! In one line... [center]Cookyx.com :: Simple LAN Chat[/center]
Authenticity Posted February 7, 2009 Posted February 7, 2009 #include <guilistview.au3> Dim $iCount = 0 Dim $GUI = GUICreate('Test', 500, 480, 100, 40) Dim $BT1 = GUICtrlCreateButton('Add1', 10, 10, 60, 20) Dim $BT2 = GUICtrlCreateButton('Add2', 80, 10, 60, 20) Dim $hListView = _GUICtrlListView_Create($GUI, 'User:|Speak:', 20, 50, 460, 400) _GUICtrlListView_AddItem($hListView, '') GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case -3 ExitLoop Case $BT1 _GUICtrlListView_SetItem($hListView, 'John', $iCount) _GUICtrlListView_SetItem($hListView, 'See', $iCount, 1) _GUICtrlListView_AddItem($hListView, '') $iCount += 1 Case $BT2 _GUICtrlListView_SetItem($hListView, 'Lisa', $iCount) _GUICtrlListView_SetItem($hListView, 'Me', $iCount, 1) _GUICtrlListView_AddItem($hListView, '') $iCount += 1 EndSwitch WEnd GUIDelete($GUI) Exit Something like this?
JavaScript_Freek Posted February 8, 2009 Author Posted February 8, 2009 No, see the post above yours. [center]Cookyx.com :: Simple LAN Chat[/center]
jvanegmond Posted February 8, 2009 Posted February 8, 2009 No, see the post above yours.Uses an embedded IE window to display chat, maybe have a look as an alternative: http://www.autoitscript.com/forum/index.php?showtopic=40943 github.com/jvanegmond
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