Jump to content

Recommended Posts

Posted (edited)

i every one i need help for my new project this project called simple land chat

this my problem see the picture below

post-45835-12691607432008_thumb.jpg

i want to see the name of the online in my chat box and if i click her name it will pop up a new window sow i can chat the user in privet

her my code

;include files
#include <GuiConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>


;define variables
Global $hGui, $hEdit, $hInp, $hBtn, $username, $rsock, $ssock, $recv
Global $port = 7892
Global $Broadcast = StringLeft(@IPAddress1, StringInStr(@IPAddress1, ".", 0, 3)) & "255"



$hGui = GUICreate("catague", 528, 263, 260, 218)
$hEdit = GUICtrlCreateEdit("", 8, 16, 289, 209,BitOR($ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL,$ES_AUTOVSCROLL))
GUICtrlSetBkColor(-1, 0xFFFFFF)

$hInp = GUICtrlCreateInput("", 8, 232, 209, 21)
$Group1 = GUICtrlCreateGroup("", 304, 120, 217, 105)
$Label1 = GUICtrlCreateLabel("Chat Name", 312, 144, 57, 17)
$Input1 = GUICtrlCreateInput("Input1", 376, 144, 137, 21)
$Button2 = GUICtrlCreateButton("Connect", 376, 192, 75, 25, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$hBtn = GUICtrlCreateButton("Send", 224, 232, 67, 25, $BS_DEFPUSHBUTTON)
$List1 = GUICtrlCreateList("7", 312, 16, 201, 97)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
        _main()
    
    EndSwitch
WEnd
;start main function
Func _main()
    ;get username
    $username = GUICtrlRead($Input1)
    If $username = "" Then
        MsgBox(16,"Error","A username must be entered.")
        Return
    EndIf
GUICtrlSetState($hEdit, $GUI_ENABLE)
GUICtrlSetState($hBtn, $GUI_ENABLE)
GUICtrlSetState($hInp, $GUI_ENABLE)
GUICtrlSetState($Button2 , $GUI_DISABLE)
    ;start winsock for udp
    UDPStartup()
    ;bind a socket to the port for listening
    $rsock = UDPBind(@IpAddress1,$port)
    If @error <> 0 Then Exit
    ;send message informing of online status
    
    SendMsg("-"&$username&"-  join the room."@CRLF&)
    SoundPlay(@WindowsDir & "\media\tada.wav",0)
    
    ;start gui loop
    Do
        $recv = UDPRecv($rsock,1024)
        If $recv <> "" Then
            Print($recv)
        EndIf
        $msg = GUIGetMsg()
        If $msg = $hBtn Then
            $buffer = GUICtrlRead($hInp)
            If $buffer <> "" Then
                GUICtrlSetData($hInp,"")
                SendMsg("["&$username&"] >: "&$buffer)
            EndIf
        EndIf
    Until $msg = $GUI_EVENT_CLOSE
    Exit
EndFunc ;==> _main

Func SendMsg($txtMsg)
        $ssock = UDPOpen($Broadcast,$port)
        If @error = 0 Then
            UDPSend($ssock,$txtMsg)
        EndIf
        UDPCloseSocket($ssock)
EndFunc ;==> SendMsg

Func Print($txtMsg)
    _GUICtrlEdit_AppendText($hEdit,@CRLF&$txtMsg)
EndFunc ;==> Print

Func OnAutoItExit()
    ;send message informing of offline status
    MsgBox(0,"","")
    SendMsg("["&$username&"] left the room.")
    UDPShutdown()
EndFunc ;==> OnAutoItExit

Please Help me. to fix my code and work properly

Edited by Gerald

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
×
×
  • Create New...