Sign in to follow this  
Followers 0
alien13

Chat Help

4 posts in this topic

Hey,

I made a chat program today at school for me and my friends to use via the network. I finished it off just then, but, when it autoscrolls the edit box and it updates it moves back to the top instead of to the bottom, is there a way to fix this?

Here is the code:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=DPS Chat.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Allow_Decompile=n
#AutoIt3Wrapper_Res_Description=DPS Chat
#AutoIt3Wrapper_Res_Fileversion=0.0.0.2
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=DPS - All rights reserved!
#AutoIt3Wrapper_Res_Language=3081
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
Global $Msg, $Field
AdlibEnable("_Update", 1000)

$Time = @HOUR & ":" & @MIN & ":" & @SEC
$ReadTxt = FileRead(@ScriptDir & "\Text.txt")


$UF = GUICreate("User Dialog", 251, 93)
$UserName = GUICtrlCreateInput("", 8, 32, 233, 21)
$OK = GUICtrlCreateButton("OK", 166, 64, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("Enter Username", 8, 12, 77, 17)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
            GUISetState(@SW_HIDE, $UF)
            _Chat()
    EndSwitch
WEnd

Func _Chat()
    $Main = GUICreate("Chat", 328, 405)
    $Msg = GUICtrlCreateEdit($ReadTxt, 8, 8, 305, 257, BitOR($GUI_SS_DEFAULT_EDIT, $ES_WANTRETURN, $ES_READONLY, $ES_AUTOVSCROLL), $WS_EX_TRANSPARENT)
    $Field = GUICtrlCreateEdit("", 8, 272, 305, 97, $ES_WANTRETURN)
    $Send = GUICtrlCreateButton("Send", 112, 374, 75, 25, 0)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Send
                If GUICtrlRead($Field) = "" Then
                    MsgBox(0, "Error!", "You didn't type a msg!")
                Else
                    GUICtrlSetData($Msg, "(" & $Time & ") " & GUICtrlRead($UserName) & " says: " & GUICtrlRead($Field) & @CRLF, 0)
                    FileWrite(@ScriptDir & "\Text.txt", "(" & $Time & ") " & GUICtrlRead($UserName) & " says: " & GUICtrlRead($Field) & @CRLF)
                    GUICtrlSetData($Field, "")
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>_Chat

Func _Update()
    $ReadTxt1 = FileRead(@ScriptDir & "\Text.txt")
    GUICtrlSetData($Msg, $ReadTxt1)
EndFunc   ;==>_Update

I have to go to work, so im in a hurry, hope this makes sense.

Just fill up the edit box with messages and wait to see what I mean.

Thanks, alien13


Share this post


Link to post
Share on other sites



The problem is in the _Update function. Use _GUICtrlEdit_AppendText() (Needs Beta) to send the text and scroll:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=DPS Chat.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Allow_Decompile=n
#AutoIt3Wrapper_Res_Description=DPS Chat
#AutoIt3Wrapper_Res_Fileversion=0.0.0.2
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=DPS - All rights reserved!
#AutoIt3Wrapper_Res_Language=3081
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <GUIEdit.au3>
Global $Msg, $Field
AdlibEnable("_Update", 1000)

$Time = @HOUR & ":" & @MIN & ":" & @SEC
$ReadTxt = FileRead(@ScriptDir & "\Text.txt")


$UF = GUICreate("User Dialog", 251, 93)
$UserName = GUICtrlCreateInput("", 8, 32, 233, 21)
$OK = GUICtrlCreateButton("OK", 166, 64, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("Enter Username", 8, 12, 77, 17)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
            GUISetState(@SW_HIDE, $UF)
            _Chat()
    EndSwitch
WEnd

Func _Chat()
    $Main = GUICreate("Chat", 328, 405)
    $Msg = GUICtrlCreateEdit($ReadTxt, 8, 8, 305, 257, BitOR($GUI_SS_DEFAULT_EDIT, $ES_WANTRETURN, $ES_READONLY, $ES_AUTOVSCROLL), $WS_EX_TRANSPARENT)
    $Field = GUICtrlCreateEdit("", 8, 272, 305, 97, $ES_WANTRETURN)
    $Send = GUICtrlCreateButton("Send", 112, 374, 75, 25, 0)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Send
                If GUICtrlRead($Field) = "" Then
                    MsgBox(0, "Error!", "You didn't type a msg!")
                Else
                    _GUICtrlEdit_AppendText($Msg, "(" & $Time & ") " & GUICtrlRead($UserName) & " says: " & GUICtrlRead($Field) & @CRLF)
;~                     GUICtrlSetData($Msg, "(" & $Time & ") " & GUICtrlRead($UserName) & " says: " & GUICtrlRead($Field) & @CRLF, 0)
                    FileWrite(@ScriptDir & "\Text.txt", "(" & $Time & ") " & GUICtrlRead($UserName) & " says: " & GUICtrlRead($Field) & @CRLF)
                    GUICtrlSetData($Field, "")
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>_Chat

Func _Update()
    $ReadTxt1 = FileRead(@ScriptDir & "\Text.txt")
;~     GUICtrlSetData($Msg, $ReadTxt1)
EndFunc   ;==>_Update

You are gonna have to figure out a different way of updating the message field. I suppose you are using TCP functions, so instead of refreshing the message field use TCPRecv() and append new text IF it has been sent.

Share this post


Link to post
Share on other sites

That is great! Man, is possible to make like in MSN, to disable button if did'n typed message in edit and when type to enable button ?!


[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites

@Nahuel - Ok, I will have a look at that function! I'm not using TCP functions to do this just simple writing to a text file and the editbox and reading it back. I suppose I could look at doing it with TCP functions, but not sure if it would work too well at school. Thanks

@n3nE - You mean like:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=DPS Chat.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Allow_Decompile=n
#AutoIt3Wrapper_Res_Description=DPS Chat
#AutoIt3Wrapper_Res_Fileversion=0.0.0.2
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=DPS - All rights reserved!
#AutoIt3Wrapper_Res_Language=3081
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
Global $Msg, $Field
AdlibEnable("_Update", 1000)

$Time = @HOUR & ":" & @MIN & ":" & @SEC
$ReadTxt = FileRead(@ScriptDir & "\Text.txt")


$UF = GUICreate("User Dialog", 251, 93)
$UserName = GUICtrlCreateInput("", 8, 32, 233, 21)
$OK = GUICtrlCreateButton("OK", 166, 64, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("Enter Username", 8, 12, 77, 17)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
            GUISetState(@SW_HIDE, $UF)
            _Chat()
    EndSwitch
WEnd

Func _Chat()
    $Main = GUICreate("Chat", 328, 405)
    $Msg = GUICtrlCreateEdit($ReadTxt, 8, 8, 305, 257, BitOR($GUI_SS_DEFAULT_EDIT, $ES_WANTRETURN, $ES_READONLY, $ES_AUTOVSCROLL), $WS_EX_TRANSPARENT)
    $Field = GUICtrlCreateEdit("", 8, 272, 305, 97, $ES_WANTRETURN)
    $Send = GUICtrlCreateButton("Send", 112, 374, 75, 25, 0)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Send
                If GUICtrlRead($Field) = "" Then
                    MsgBox(0, "Error!", "You didn't type a msg!")
                Else
                    GUICtrlSetData($Msg, "(" & $Time & ") " & GUICtrlRead($UserName) & " says: " & GUICtrlRead($Field) & @CRLF, 0)
                    FileWrite(@ScriptDir & "\Text.txt", "(" & $Time & ") " & GUICtrlRead($UserName) & " says: " & GUICtrlRead($Field) & @CRLF)
                    GUICtrlSetData($Field, "")
                    GUICtrlSetState($Send, $GUI_DISABLE)
                EndIf
        EndSwitch
        If GUICtrlRead($Field) = "" Then
        Else
            GUICtrlSetState($Send, $GUI_ENABLE)
        EndIf
    WEnd
EndFunc   ;==>_Chat

Func _Update()
    $ReadTxt1 = FileRead(@ScriptDir & "\Text.txt")
    GUICtrlSetData($Msg, $ReadTxt1)
EndFunc   ;==>_Update

Not sure how to stop the flashing atm, just got home from work, and am tired atm..

alien13


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