Jump to content
Sign in to follow this  
therks

Simple "chat" program with clickable links

Recommended Posts

Thanks, @therks. Eventually, I made it that way as you suggested.

I made a user.ini text file wherein all users that will run the program it will automatically log to that "user.ini" using FileWrite() function and when they close the program, it will automatically delete the string match of the username that closes the program and be deleted in user.ini file. In that way, I can use _FileReadToArray to add these users in your GUI,:> and currently working on it.

Thanks again for the idea.:lol:

I'll share the outcome after.^_^

 

KS15


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites

@therks,

:sweating: My added code is not good as it was I think...:lol: But can you try if that's Okay? Just add some dummy usernames in the User.ini file to see if it work. If you like, you can also modify my added codes just to make it more presentable^_^ and for my convenience....:>

#include <GUIConstants.au3>
#include <GUIEdit.au3>
#include <IE.au3>
#include <GuiRichEdit.au3>
#include <ColorConstants.au3>
#include <GUIConstants.au3>
#include <GUIEdit.au3>
#include <IE.au3>
#include <GuiRichEdit.au3>
#Include <Array.au3>
#Include <File.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Opt('TrayIconDebug', 1)

If $CmdLine[0] And StringInStr(FileGetAttrib($CmdLine[1]), 'D') Then
    FileChangeDir($CmdLine[1])
EndIf

Global $CHAT_FILE = @ScriptDir & '\NetworkChat.txt'
ConsoleWrite($CHAT_FILE & @CRLF)

Global $UserPath = @ScriptDir & '\User.ini'

Local $hFileOpen = FileOpen($UserPath, $FO_APPEND)
If $hFileOpen = -1 Then
   MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
   Return False
EndIf
FileWrite($UserPath, @UserName)
FileClose($hFileOpen)

Local $xFileOpen = FileOpen($UserPath, $FO_READ)
If $xFileOpen = -1 Then
   MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
   Return False
EndIf
Local $sFileRead = FileRead($xFileOpen)
FileClose($xFileOpen)

Main()

Func Main()
    Local $hGUIMain = GUICreate('Network Chat', 570, 440, Default, Default, $WS_OVERLAPPEDWINDOW)

    Local $oEmbedIE = _IECreateEmbedded()
    Local $ob_EmbedIE = GUICtrlCreateObj($oEmbedIE, 5, 5, 490, 300)
        GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

    _IENavigate($oEmbedIE, 'about:blank')

    Local $dm_AccelTab = GUICtrlCreateDummy()
    Local $dm_AccelCtrlA = GUICtrlCreateDummy()
    Local $dm_AccelEnter = GUICtrlCreateDummy()
    Local $dm_AccelShiftEnter = GUICtrlCreateDummy()
    Local $dm_AccelPgUp = GUICtrlCreateDummy()
    Local $dm_AccelPgDn = GUICtrlCreateDummy()
    Local $ed_Chat = GUICtrlCreateEdit('', 5, 310, 470, 60, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
        GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
        Local $aTabStop = [ 4 * 4 ]
        _GUICtrlEdit_SetTabStops($ed_Chat, $aTabStop)
    Local $bt_Send = GUICtrlCreateButton('>', 475, 310, 20, 60)
        GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
        GUICtrlSetState(-1, $GUI_DEFBUTTON)

    Local $ch_Timestamps = GUICtrlCreateCheckbox('Show &timestamps', 5, 375, 200, 20)
        GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKLEFT))
    Local $ch_PromptURL = GUICtrlCreateCheckbox('&Confirm before opening links', 5, 395, 200, 20)
        GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKLEFT))
    Local $ra_Enter = GUICtrlCreateRadio('&1. Enter to send / Shift+Enter for new line', 280, 375, 215, 20)
        GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
        GUICtrlSetState(-1, $GUI_CHECKED)
    Local $ra_ShiftEnter = GUICtrlCreateRadio('&2. Shift+Enter to send / Enter for new line', 280, 395, 215, 20)
        GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
    Local $lb_Status = GUICtrlCreateLabel(' Chat file: ' & $CHAT_FILE, 0, 420, 500, 20, BitOR($SS_SUNKEN, $SS_CENTERIMAGE))
        GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
        GUICtrlSetCursor(-1, 0)
    Local $UsrIn = GUICtrlCreateLabel($sFileRead, 500, 20)
                  GUICtrlSetColor($UsrIn, $COLOR_GREEN)
    Local $UsrGrp = GUICtrlCreateGroup("Active User:", 495, 5,72,300)
    Local $aAccel = [ _
        [ '{enter}', $dm_AccelEnter ], _
        [ '+{enter}', $dm_AccelShiftEnter ], _
        [ '{tab}', $dm_AccelTab ], _
        [ '{pgup}', $dm_AccelPgUp ], _
        [ '{pgdn}', $dm_AccelPgDn ], _
        [ '^a', $dm_AccelCtrlA ] ]

    GUISetAccelerators($aAccel)
    GUISetState()
    GUICtrlSetState($ed_Chat, $GUI_FOCUS)


    Local $sHTML, $aChatTime[2], $hFocused, $hIEControl = ControlGetHandle($hGUIMain, '', '[CLASS:Internet Explorer_Server; INSTANCE:1]')
    While 1
        $hFocused = _WinAPI_GetFocus()

        $aChatTime[0] = FileGetTime($CHAT_FILE, 0, 1)
        If $aChatTime[0] <> $aChatTime[1] Then
            $sHTML = _LoadChat(BitAND(GUICtrlRead($ch_Timestamps), $GUI_CHECKED))
            _IEDocWriteHTML($oEmbedIE, $sHTML)
            _IEAction($oEmbedIE, 'refresh')
            $oEmbedIE.document.parentwindow.scrollTo(0, $oEmbedIE.document.body.scrollHeight)
            $aChatTime[1] = $aChatTime[0]
        EndIf

        If $oEmbedIE.document.location.href <> 'about:blank' Then
            _IENavigate($oEmbedIE, 'about:blank')
            $aChatTime[1] = 0
        EndIf

        Local $oAutoItMonitor = $oEmbedIE.document.getElementById('autoit_monitor')
        If IsObj($oAutoItMonitor) And $oAutoItMonitor.value Then
            Local $sVal = $oAutoItMonitor.value
            If StringLeft($sVal, 4) = 'http' Then
                Local $sVal = StringReplace($sVal, '&amp;', '&') ; For some reason the JavaScript copying the URL always encodes ampersands to html entities
                If Not BitAND(GUICtrlRead($ch_PromptURL), $GUI_CHECKED) Or (MsgBox(0x124, 'URL', 'Open URL?' & @LF & $sVal, 0, $hGUIMain) = 6) Then
                    ShellExecute($sVal)
                EndIf
            ElseIf $sVal = 27 Then ; Escape
                ExitLoop
            ElseIf Not ($sVal = 17 Or $sVal >= 35 And $sVal <= 40) Then ; Ctrl, Home, End, Arrow keys
                ConsoleWrite($sVal & @CRLF)
                GUICtrlSetState($ed_Chat, $GUI_FOCUS)
            EndIf
            $oAutoItMonitor.value = ''
        EndIf

        Local $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $lb_Status
                ShellExecute($CHAT_FILE)
            Case $ch_Timestamps
                $aChatTime[1] = 0
            Case $dm_AccelPgUp
                $oEmbedIE.document.parentwindow.scrollBy(0, -200)
            Case $dm_AccelPgDn
                $oEmbedIE.document.parentwindow.scrollBy(0, 200)
            Case $dm_AccelCtrlA
                If $hFocused = GUICtrlGetHandle($ed_Chat) Then _GUICtrlEdit_SetSel($ed_Chat, 0, -1)
            Case $dm_AccelEnter
                If $hFocused = GUICtrlGetHandle($ed_Chat) Then
                    If BitAND(GUICtrlRead($ra_Enter), $GUI_CHECKED) Then
                        _SendChat($ed_Chat)
                    Else
                        _GUICtrlEdit_ReplaceSel($ed_Chat, @CRLF)
                    EndIf
                EndIf
            Case $dm_AccelShiftEnter
                If $hFocused = GUICtrlGetHandle($ed_Chat) Then
                    If BitAND(GUICtrlRead($ra_ShiftEnter), $GUI_CHECKED) Then
                        _SendChat($ed_Chat)
                    Else
                        _GUICtrlEdit_ReplaceSel($ed_Chat, @CRLF)
                    EndIf
                EndIf
            Case $bt_Send
                _SendChat($ed_Chat)
            Case $dm_AccelTab
                If $hFocused = GUICtrlGetHandle($ed_Chat) Then
                    _GUICtrlEdit_ReplaceSel($ed_Chat, @TAB)
                Else
                    GUICtrlSetState($ed_Chat, $GUI_FOCUS)
                EndIf
            Case $GUI_EVENT_CLOSE
               Global $_Array
               _FileReadToArray ( @ScriptDir & '\User.ini', $_Array )
               $_Array = _DeleteArrayElementWithStringInstr ( $_Array, @UserName )
               _FileWriteFromArray (@ScriptDir & '\User.ini', $_Array, 1 )
                ExitLoop
        EndSwitch
    WEnd
EndFunc

Func _DeleteArrayElementWithStringInstr ( $_Array, $_String )
    Local $_Item
    For $_Element In $_Array
        If StringInStr ( $_Element, $_String ) <> 0 Then
            _ArrayDelete ( $_Array, $_Item )
        Else
            $_Item+=1
        EndIf
    Next
    Return ( $_Array )
EndFunc

Func _EncodeForFile($sString)
    $sString = StringStripCR($sString)
    $sString = StringReplace($sString, '\', '\\')
    $sString = StringReplace($sString, @LF, '\n')
    $sString = StringReplace($sString, @TAB, '\t')
    Return $sString
EndFunc

Func _EncodeFromFile($sString)
    $sString = StringReplace($sString, '<', '&lt;')
    $sString = StringReplace($sString, '>', '&gt;')
    $sString = StringFormat($sString)
    $sString = StringReplace($sString, @TAB, '&nbsp;&nbsp;&nbsp;&nbsp;')
    $sString = StringReplace($sString, @LF, '<br />')
    $sString = StringRegExpReplace($sString, '(https?://\S+)', '<span class="fakelink" onclick="document.getElementById(''autoit_monitor'').value=this.innerHTML">\1</span>') ;
    Return $sString
EndFunc

Func _SendChat($iCtrl)
    Local $sChat = StringStripWS(GUICtrlRead($iCtrl), 3)
    If $sChat Then
        FileWrite($CHAT_FILE, @CRLF & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @TAB & @ComputerName & @TAB & _EncodeForFile($sChat))
        GUICtrlSetData($iCtrl, '')
        Return True
    EndIf
EndFunc

Func _LoadChat($iShowTS)
    Local $aLines = FileReadToArray($CHAT_FILE), _
    $sOutput  = '<style>' & @CRLF
    $sOutput &= 'body, table { margin: 0; font-family: Arial; font-size: 0.8em; border-collapse: collapse; width: 100%; } ' & @CRLF
    $sOutput &= 'tr { vertical-align: top; text-align: left; } ' & @CRLF
    $sOutput &= '.name_column { white-space: nowrap; } ' & @CRLF
    $sOutput &= '.text_column { width: 100%; } ' & @CRLF
    $sOutput &= '.row1 { background: #eee; } ' & @CRLF
    $sOutput &= '.date { background: #bef; text-align: center; border: solid #000; border-width: 1px 0; } ' & @CRLF
    $sOutput &= '.fakelink { text-decoration: underline; cursor: pointer; color: #08f; } ' & @CRLF
    If Not $iShowTS Then $sOutput &= '.timestamp { display: none }' & @CRLF
    $sOutput &= '</style>' & @CRLF
    $sOutput &= '<body onkeydown="document.getElementById(''autoit_monitor'').value=event.keyCode">' & @CRLF
    $sOutput &= '<table>' & @CRLF

    Local $sDateMem
    For $L = 0 To @extended-1
        If Not $aLines[$L] Then ContinueLoop

        Local $aRegExLine = StringRegExp($aLines[$L], '(.+)\t(.+)\t(.+)', 1), $sChat
        If Not @error Then
            $aDateTime = _FormatTime($aRegExLine[0])
            If $aDateTime[0] <> $sDateMem Then
                $sOutput &= '<tr><th class="date" colspan="2">' & $aDateTime[0] & '</th></tr>'
                $sDateMem = $aDateTime[0]
            EndIf

            $sOutput &= '<tr class="row' & Mod($L, 2) & '">' & _
                '<th class="name_column"><span class="timestamp">[' & $aDateTime[1] & '] </span>&lt;' & $aRegExLine[1] & '&gt;</th>' & _
                '<td class="text_column">' & _EncodeFromFile($aRegExLine[2]) & '</td></tr>' & @CRLF
        EndIf
    Next
    $sOutput &= '</table>'
    $sOutput &= '<input type="hidden" id="autoit_monitor" />'
    Return $sOutput
EndFunc

Func _FormatTime($sTime)
    Local $aMonths = StringSplit('Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec', '|')
    Local $aReturn[2]
    Local $aRegEx = StringRegExp($sTime, '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})', 1)
    If Not @error Then
        $aReturn[0] = $aRegEx[0] &'-'& $aMonths[Int($aRegEx[1])] &'-'& $aRegEx[2]
        $aReturn[1] = $aRegEx[3] &':'& $aRegEx[4] &':'& $aRegEx[5]
    EndIf
    Return $aReturn
EndFunc

 

KS15


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites

That looks like a good start.

A few things I noticed:

  • You should add a line ending to the username when you add it to the file [ FileWrite($UserPath, @UserName & @CRLF) ], otherwise the next name added will be on the same line.
  • When you're exiting the script, the line: _FileWriteFromArray (@ScriptDir & '\User.ini', $_Array, 1 ) will not write an empty array to file when the last user has been removed, instead it will just fail and that last username will be left in the file. Perhaps do a check if the array is empty, and then manually overwrite the user.ini, or even just delete it.
  • I would maybe shrink the display area a bit, so your username list will fit better beside it. Also you need to set the sizing properties for that list.
  • You also need to keep re-reading the username file and putting it in that Label control otherwise when a new user logs on, none of the existing users will see them.

 

Edited by therks

Share this post


Link to post
Share on other sites

@therks,

On 5/5/2018 at 10:54 PM, therks said:

You should add a line ending to the username when you add it to the file [ FileWrite($UserPath, @UserName & @CRLF) ], otherwise the next name added will be on the same line.

Yup noticed that one too and I already made it corrected accordingly. ^_^

 

On 5/5/2018 at 10:54 PM, therks said:

When you're exiting the script, the line: _FileWriteFromArray (@ScriptDir & '\User.ini', $_Array, 1 ) will not write an empty array to file when the last user has been removed, instead it will just fail and that last username will be left in the file. Perhaps do a check if the array is empty, and then manually overwrite the user.ini, or even just delete it.

definitely true, when it reaches to the last user, that code won't removed the last user but instead, it will fail. Yup, made it there as well thanks for checking.:D

 

On 5/5/2018 at 10:54 PM, therks said:

I would maybe shrink the display area a bit, so your username list will fit better beside it. Also you need to set the sizing properties for that list.

Okay, I'll check on this and see if I can shrink it a bit.

 

On 5/5/2018 at 10:54 PM, therks said:

You also need to keep re-reading the username file and putting it in that Label control otherwise when a new user logs on, none of the existing users will see them.

Yup and this is where i was stacked for a while. I tried adding it in the loop but the close event was affected with it, so I tried having a separate loop While 1.... WEnd but still having issue with the enter section and the loop continuously looping, So what I did is I added the re-reading part when the enter key was hit by the user. I mean, every time the user hits enter, the FileRead() function will continue reading. Hahaha a silly idea but could not think for one way to solve this.:sweating:

 


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites

I don't know if you're still interested in this @KickStarter15, but I kept modifying my code and I eventually decided to add a userlist as well.

Maybe you'll find something interesting.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=NetworkChat.ico
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Fileversion=1.0.0.21
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <WinAPISys.au3>
#include <WinAPIsysinfoConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ListBoxConstants.au3>
#include <TrayConstants.au3>
#include <GUIEdit.au3>
#include <GuiListView.au3>
#include <IE.au3>
#include <Date.au3>

If $CmdLine[0] And StringInStr(FileGetAttrib($CmdLine[1]), 'D') Then
    FileChangeDir($CmdLine[1])
EndIf

Global Const $SINGLETON_TITLE = String(StringToBinary('therks - Network Chat')), _
    $APP_NAME = 'Network Chat', _
    $USER_NAME = @ComputerName, _
    $CHAT_FILE = @WorkingDir & '\NetworkChat.txt', _
    $USER_FILE = @WorkingDir & '\NetworkChatUsers.ini', _
    $CSS_FILE = @AppDataDir & '\NetworkChat.css', _
    $INI_FILE = @AppDataDir & '\NetworkChat.ini', $INI_SECTION = 'CONFIG', $INI_HISTORY = 'History', _
    $INI_ENTERSTYLE = 'EnterStyle', $INI_ONTOP = 'OnTop', $INI_STARTMIN = 'StartMin', $INI_MINTOTRAY = 'MinToTray', $INI_CLOSEMIN = 'CloseMin', $INI_SHOWUSERS = 'ShowUsers', _
    $INI_ESCCLOSE = 'EscClose', $INI_SHOWTIMES = 'ShowTimes', $INI_CONFIRMLINK = 'ConfirmLink'

Global Enum $GLOBAL_WIN, $GLOBAL_EMBED, $GLOBAL_TOGGLE, $GLOBAL_UB
Global $GLOBAL_ARRAY[$GLOBAL_UB]

Global $HISTORY_LIST[11]

Main()

Func Main()
    If 'Singleton window' Then
        If WinExists($SINGLETON_TITLE) Then
            ControlSetText('[last]', '', 'Edit1', 'Show')
            Exit
        EndIf
        GUICreate($SINGLETON_TITLE)
        Local $ed_Singleton = GUICtrlCreateEdit('', 0, 0)
    EndIf

    Opt('MustDeclareVars', 1)
    Opt('TrayMenuMode', 3)
    TraySetToolTip($APP_NAME)
    TraySetState()

    _CSSFile()

    Local $iCfgEnterStyle = Int(IniRead($INI_FILE, $INI_SECTION, $INI_ENTERSTYLE, 0))
    Local $iCfgShowTimes = Int(IniRead($INI_FILE, $INI_SECTION, $INI_SHOWTIMES, 0))
    Local $iCfgConfirmLink = Int(IniRead($INI_FILE, $INI_SECTION, $INI_CONFIRMLINK, 0))
    Local $iCfgEscKeyClose = Int(IniRead($INI_FILE, $INI_SECTION, $INI_ESCCLOSE, 0))
    Local $iCfgStartMin = Int(IniRead($INI_FILE, $INI_SECTION, $INI_STARTMIN, 0))
    Local $iCfgMinToTray = Int(IniRead($INI_FILE, $INI_SECTION, $INI_MINTOTRAY, 0))
    Local $iCfgCloseMin = Int(IniRead($INI_FILE, $INI_SECTION, $INI_CLOSEMIN, 0))
    Local $iCfgOnTop = Int(IniRead($INI_FILE, $INI_SECTION, $INI_ONTOP, 0))
    Local $iCfgShowUsers = Int(IniRead($INI_FILE, $INI_SECTION, $INI_SHOWUSERS, 1))

    If 'Tray Menu Setup' Then ; =========================================================================================================
        TraySetClick(16)
        Local $ti_Open, $ti_Exit
        $ti_Open = TrayCreateItem('&Open')
            TrayItemSetState(-1, $TRAY_DEFAULT)
        $ti_Exit = TrayCreateItem('E&xit')
    EndIf ; =========================================================================================================

    Local $aTabStop = [ 4 * 4 ]
    If 'Main window' Then ; ============================================================================================================
        Local Enum $ACC_CTRL_TAB, $ACC_CTRL_A, $ACC_ENTER, $ACC_SHIFT_ENTER, $ACC_PGUP, $ACC_PGDN, $ACC_CTRL_UP, $ACC_CTRL_DN, $ACC_ESC, $ACC_UB
        Local $hGUIMain, $oEmbeddedIE, $ob_EmbedIE, $li_Users, $dm_Accel[$ACC_UB], $bt_Options, $ed_Chat, $bt_Send, $lb_Status

        $hGUIMain = GUICreate($APP_NAME, 500, 415, Default, Default, $WS_OVERLAPPEDWINDOW)

        $oEmbeddedIE = _IECreateEmbedded()
        $ob_EmbedIE = GUICtrlCreateObj($oEmbeddedIE, 0, 0, 400, 310)
        $li_Users = GUICtrlCreateList('', 405, 0, 95, 310, BitOR($LBS_NOINTEGRALHEIGHT, $LBS_SORT, $LBS_NOSEL))
            GUICtrlSetResizing(-1, BitOR(BitXOR($GUI_DOCKBORDERS, $GUI_DOCKLEFT), $GUI_DOCKWIDTH))
        If Not $iCfgShowUsers Then
            GUICtrlSetState(-1, $GUI_HIDE)
        EndIf

        _IENavigate($oEmbeddedIE, 'about:blank')

        $dm_Accel[$ACC_CTRL_TAB]    = GUICtrlCreateDummy()
        $dm_Accel[$ACC_CTRL_A]      = GUICtrlCreateDummy()
        $dm_Accel[$ACC_ENTER]       = GUICtrlCreateDummy()
        $dm_Accel[$ACC_SHIFT_ENTER] = GUICtrlCreateDummy()
        $dm_Accel[$ACC_PGUP]        = GUICtrlCreateDummy()
        $dm_Accel[$ACC_PGDN]        = GUICtrlCreateDummy()
        $dm_Accel[$ACC_CTRL_UP]     = GUICtrlCreateDummy()
        $dm_Accel[$ACC_CTRL_DN]     = GUICtrlCreateDummy()
        $dm_Accel[$ACC_ESC]         = GUICtrlCreateDummy()

        $bt_Options = GUICtrlCreateButton('+', 480, 315, 20, 20)
            GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
            GUICtrlSetTip(-1, 'Options (Alt+O)')
        $ed_Chat = GUICtrlCreateEdit('', 0, 315, 480, 80, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
            GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
            _GUICtrlEdit_SetTabStops($ed_Chat, $aTabStop)
        $bt_Send = GUICtrlCreateButton('>', 480, 335, 20, 60)
            GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
            GUICtrlSetState(-1, $GUI_DEFBUTTON)

        $lb_Status = GUICtrlCreateLabel(' Chat file: ' & $CHAT_FILE, 0, 395, 500, 20, BitOR($SS_SUNKEN, $SS_CENTERIMAGE))
            GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
            GUICtrlSetCursor(-1, 0)
    EndIf ; =============================================================================================================================

    If 'Options Window' Then ; =========================================================================================================
        Local $hGUIOptions, $ra_EnterStyleNoShift, $ra_EnterStyleShift, $ch_OnTop, $ch_StartMin, $ch_MinToTray, $ch_CloseMin, $ch_EscKeyClose, $ch_Timestamps, $ch_ShowUsers, $ch_ConfirmLink, $ch_RawHTML, $bt_CSS, $bt_CSSReset

        $hGUIOptions = GUICreate('Options', 240, 275, Default, Default, BitOR($WS_CAPTION, $WS_SYSMENU), $WS_EX_TOOLWINDOW, $hGUIMain)

        GUICtrlCreateGroup('&Enter key behaviour:', 5, 5, 230, 60)
        $ra_EnterStyleNoShift = GUICtrlCreateRadio('Enter to send (Shift+Enter for new line)', 10, 20, 215, 20)
            GUICtrlSetState(-1, $GUI_CHECKED)
        $ra_EnterStyleShift = GUICtrlCreateRadio('Shift+Enter to send (Enter for new line)', 10, 40, 215, 20)
            If $iCfgEnterStyle Then GUICtrlSetState(-1, $GUI_CHECKED)

        $ch_OnTop = GUICtrlCreateCheckbox('Keep &window on top', 5, 70, 200, 20)
            If $iCfgOnTop Then GUICtrlSetState(-1, $GUI_CHECKED)
        $ch_StartMin = GUICtrlCreateCheckbox('&Start minimized/hidden', 5, 90, 215, 20)
            If $iCfgStartMin Then GUICtrlSetState(-1, $GUI_CHECKED)
        $ch_MinToTray = GUICtrlCreateCheckbox('&Minimize to tray (hide)', 5, 110, 200, 20)
            If $iCfgMinToTray Then GUICtrlSetState(-1, $GUI_CHECKED)
        $ch_CloseMin = GUICtrlCreateCheckbox('&Close minimizes', 5, 130, 215, 20)
            If $iCfgCloseMin Then GUICtrlSetState(-1, $GUI_CHECKED)
        $ch_EscKeyClose = GUICtrlCreateCheckbox('Escape &key closes', 5, 150, 215, 20)
            If $iCfgEscKeyClose Then GUICtrlSetState(-1, $GUI_CHECKED)
        $ch_ShowUsers = GUICtrlCreateCheckbox('Show &users', 5, 170, 200, 20)
            If $iCfgShowUsers Then GUICtrlSetState(-1, $GUI_CHECKED)
        $ch_Timestamps = GUICtrlCreateCheckbox('Show &timestamps', 5, 190, 200, 20)
            If $iCfgShowTimes Then GUICtrlSetState(-1, $GUI_CHECKED)
        $ch_ConfirmLink = GUICtrlCreateCheckbox('Confirm &before opening links', 5, 210, 200, 20)
            If $iCfgConfirmLink Then GUICtrlSetState(-1, $GUI_CHECKED)
        $ch_RawHTML = GUICtrlCreateCheckbox('&View Chat HTML', 5, 230, 200, 20)

        $bt_CSS = GUICtrlCreateButton('Edit CSS &File', 5, 250, 115, 20)
        $bt_CSSReset = GUICtrlCreateButton('&Reset CSS File', 120, 250, 115, 20)

    EndIf ; =============================================================================================================================

    Local $aAccel = [ _
        [ '{enter}',  $dm_Accel[$ACC_ENTER] ], _
        [ '+{enter}', $dm_Accel[$ACC_SHIFT_ENTER] ], _
        [ '^{tab}',   $dm_Accel[$ACC_CTRL_TAB] ], _
        [ '{pgup}',   $dm_Accel[$ACC_PGUP] ], _
        [ '{pgdn}',   $dm_Accel[$ACC_PGDN] ], _
        [ '^{up}',    $dm_Accel[$ACC_CTRL_UP] ], _
        [ '^{down}',    $dm_Accel[$ACC_CTRL_DN] ], _
        [ '{esc}',    $dm_Accel[$ACC_ESC] ], _
        [ '^a',       $dm_Accel[$ACC_CTRL_A] ], _
        [ '!o',       $bt_Options ] _
    ]
    GUISetAccelerators($aAccel, $hGUIMain)
    $GLOBAL_ARRAY[$GLOBAL_WIN] = $hGUIMain
    $GLOBAL_ARRAY[$GLOBAL_EMBED] = $ob_EmbedIE
    $GLOBAL_ARRAY[$GLOBAL_TOGGLE] = $iCfgShowUsers
    GUIRegisterMsg($WM_GETMINMAXINFO, WM_GETMINMAXINFO)
    GUIRegisterMsg($WM_PAINT, WM_PAINT)

    If $iCfgStartMin Then
        If Not $iCfgMinToTray Then
            GUISetState(@SW_SHOWMINIMIZED, $hGUIMain)
        EndIf
    Else
        GUISetState(@SW_SHOW, $hGUIMain)
    EndIf
    GUICtrlSetState($ed_Chat, $GUI_FOCUS)

    If $iCfgOnTop Then WinSetOnTop($hGUIMain, '', 1)

    _IEErrorNotify(False)
    Local $bReload = True, $sHTML, $aChatFileTime[2], $oDoc = _IEDocGetObj($oEmbeddedIE), $oAutoItMonitor, $sMonitorValue, $iTM, $aGM, $iUserPingTimer, $sUserList, $iPing, $aUserData
    While 1
        If GUICtrlRead($ed_Singleton) Then
            GUICtrlSetData($ed_Singleton, '')
            GUISetState(@SW_SHOWNORMAL, $hGUIMain)
            WinActivate($hGUIMain)
        EndIf

        If TimerDiff($iUserPingTimer) > 2000 Then
            $iUserPingTimer = TimerInit()
            IniWrite($USER_FILE, 'Users', $USER_NAME, _NowCalc())

            $sUserList = ''
            $aUserData = IniReadSection($USER_FILE, 'Users')
            For $i = 1 To $aUserData[0][0]
                $iPing = _DateDiff('s', $aUserData[$i][1], _NowCalc())
                If $iPing > 30 Then
                    IniDelete($USER_FILE, 'Users', $aUserData[$i][0])
                EndIf
                If $aUserData[$i][0] = $USER_NAME Then $aUserData[$i][0] = '@' & $aUserData[$i][0]

                $sUserList &= '|' & $aUserData[$i][0]
                Assign('USERPING_' & StringToBinary($aUserData[$i][0]), $iPing, 2)
            Next
            GUICtrlSetData($li_Users, $sUserList)
        EndIf

        ; Check modified time on chat file, refresh if changes detected
        $aChatFileTime[0] = FileGetTime($CHAT_FILE, 0, 1)
        If $bReload Or $aChatFileTime[0] <> $aChatFileTime[1] Then
            $sHTML = _LoadChat(_IsChecked($ch_Timestamps))
            If _IsChecked($ch_RawHTML) Then
                $sHTML = StringReplace($sHTML, '<', '<')
                $sHTML = StringReplace($sHTML, '>', '>')
                $sHTML = '<pre>' & $sHTML & '</pre>'
            EndIf

            _IEDocWriteHTML($oEmbeddedIE, $sHTML)
            _IEAction($oEmbeddedIE, 'refresh')
            $oDoc = _IEDocGetObj($oEmbeddedIE)
            $oDoc.parentwindow.scrollTo(0, $oDoc.body.scrollHeight) ; Scroll to bottom
            $aChatFileTime[1] = $aChatFileTime[0]
            Local $aFormatTime = _FormatTime($aChatFileTime[0])
            GUICtrlSetData($lb_Status, ' Chat file: ' & $CHAT_FILE & ' | Last update: ' & $aFormatTime[1])
            If Not $bReload And Not WinActive($hGUIMain) Then
                TrayTip($APP_NAME, '[' & $aFormatTime[1] & '] New message', 5)
            EndIf
            $bReload = False
        EndIf

        ; If the embedded browser somehow navigates away
        If IsObj($oDoc) Then
            If $oDoc.location.href <> 'about:blank' Then
                _IENavigate($oEmbeddedIE, 'about:blank')
                $bReload = True
            EndIf

            $oAutoItMonitor = _IEGetObjById($oEmbeddedIE, 'autoit_monitor')
            If IsObj($oAutoItMonitor) And $oAutoItMonitor.value Then
                $sMonitorValue = $oAutoItMonitor.value
                If StringLeft($sMonitorValue, 4) = 'URL:' Then
                    $sMonitorValue = StringReplace(StringTrimLeft($sMonitorValue, 4), '&', '&') ; For some reason the JavaScript copying the URL always encodes ampersands to html entities
                    If Not _IsChecked($ch_ConfirmLink) Or (MsgBox(0x124, 'URL', 'Open URL?' & @LF & $sMonitorValue, 0, $hGUIMain) = 6) Then
                        ShellExecute($sMonitorValue)
                    EndIf
                ElseIf StringLeft($sMonitorValue, 4) = 'KEY:' Then
                    Switch StringTrimLeft($sMonitorValue, 4)
                        Case 27 ; Escape
                            ExitLoop
                        Case 17, 35 To 40
                            ; Do nothing - allows Ctrl, Home/End, & arrow keys
                        Case Else ; Any other key: focus edit control
                            GUICtrlSetState($ed_Chat, $GUI_FOCUS)
                    EndSwitch
                EndIf
                $oAutoItMonitor.value = '' ; Always clear monitor
            EndIf
        EndIf

        $iTM = TrayGetMsg()
        Switch $iTM
            Case $ti_Open
                GUISetState(@SW_SHOWNORMAL, $hGUIMain)
                WinActivate($hGUIMain)
            Case $ti_Exit
                _Exit()
        EndSwitch

        $aGM = GUIGetMsg(1)
        Switch $aGM[0]
            Case $li_Users
                If GUICtrlRead($li_Users) Then
                    ToolTip(GUICtrlRead($li_Users) & ' - Ping: ' & Eval('USERPING_' & StringToBinary(GUICtrlRead($li_Users))) & 's')
                EndIf
            Case $ra_EnterStyleNoShift
                $iCfgEnterStyle = 0
                IniWrite($INI_FILE, $INI_SECTION, $INI_ENTERSTYLE, $iCfgEnterStyle)
            Case $ra_EnterStyleShift
                $iCfgEnterStyle = 1
                IniWrite($INI_FILE, $INI_SECTION, $INI_ENTERSTYLE, $iCfgEnterStyle)
            Case $ch_OnTop
                $iCfgOnTop = _SetSetting($aGM[0], $INI_ONTOP)
                WinSetOnTop($hGUIMain, '', $iCfgOnTop)
            Case $ch_StartMin
                $iCfgStartMin = _SetSetting($aGM[0], $INI_STARTMIN)
            Case $ch_MinToTray
                $iCfgMinToTray = _SetSetting($aGM[0], $INI_MINTOTRAY)
            Case $ch_CloseMin
                $iCfgCloseMin = _SetSetting($aGM[0], $INI_CLOSEMIN)
            Case $ch_EscKeyClose
                $iCfgEscKeyClose = _SetSetting($aGM[0], $INI_ESCCLOSE)
            Case $ch_ShowUsers
                $iCfgShowUsers = _SetSetting($aGM[0], $INI_SHOWUSERS)
                $GLOBAL_ARRAY[$GLOBAL_TOGGLE] = $iCfgShowUsers
                If $iCfgShowUsers Then
                    GUICtrlSetState($li_Users, $GUI_SHOW)
                Else
                    GUICtrlSetState($li_Users, $GUI_HIDE)
                EndIf
            Case $ch_Timestamps
                $bReload = True ; Causes chat refresh
                $iCfgShowTimes = _SetSetting($aGM[0], $INI_SHOWTIMES)
            Case $ch_ConfirmLink
                $iCfgConfirmLink = _SetSetting($aGM[0], $INI_CONFIRMLINK)

            Case $ch_RawHTML
                $bReload = True ; Causes chat refresh
            Case $bt_CSS
                ShellExecute($CSS_FILE)
            Case $bt_CSSReset
                If _CSSFile(1) Then
                    MsgBox(0x40, 'CSS File', 'CSS file restored', 0, $hGUIOptions)
                Else
                    MsgBox(0x30, 'CSS File', 'Unable to restore CSS file', 0, $hGUIOptions)
                EndIf

            Case $dm_Accel[$ACC_PGUP]
                $oDoc.parentwindow.scrollBy(0, -200)
            Case $dm_Accel[$ACC_PGDN]
                $oDoc.parentwindow.scrollBy(0, 200)
            Case $dm_Accel[$ACC_CTRL_UP]
                GUICtrlSetData($ed_Chat, _SendHistory(1))
            Case $dm_Accel[$ACC_CTRL_DN]
                GUICtrlSetData($ed_Chat, _SendHistory(-1))
            Case $dm_Accel[$ACC_CTRL_A]
                If _IsFocused($ed_Chat) Then _GUICtrlEdit_SetSel($ed_Chat, 0, -1)
            Case $dm_Accel[$ACC_ENTER]
                If _IsFocused($ed_Chat) Then
                    If _IsChecked($ra_EnterStyleNoShift) Then
                        _SendChat($ed_Chat)
                        $bReload = True
                    Else
                        _GUICtrlEdit_ReplaceSel($ed_Chat, @CRLF)
                    EndIf
                EndIf
            Case $dm_Accel[$ACC_SHIFT_ENTER]
                If _IsFocused($ed_Chat) Then
                    If _IsChecked($ra_EnterStyleShift) Then
                        _SendChat($ed_Chat)
                        $bReload = True
                    Else
                        _GUICtrlEdit_ReplaceSel($ed_Chat, @CRLF)
                    EndIf
                EndIf
            Case $dm_Accel[$ACC_CTRL_TAB]
                If _IsFocused($ed_Chat) Then
                    _GUICtrlEdit_ReplaceSel($ed_Chat, @TAB)
                EndIf

            Case $bt_Send
                _SendChat($ed_Chat)
                $bReload = True
            Case $bt_Options
                Local $aMainPos = WinGetPos($hGUIMain)
                Local $aOptPos = WinGetPos($hGUIOptions)
                WinMove($hGUIOptions, '', _
                    $aMainPos[0]+($aMainPos[2]-$aOptPos[2])/2, _
                    $aMainPos[1]+($aMainPos[3]-$aOptPos[3])/2)
                GUISetState(@SW_SHOW, $hGUIOptions)
                WinActivate($hGUIOptions)
            Case $lb_Status
                ShellExecute($CHAT_FILE) ; Open raw chat file

            Case $dm_Accel[$ACC_ESC]
                If _IsChecked($ch_EscKeyClose) Then ContinueCase
            Case $GUI_EVENT_CLOSE
                If $aGM[1] = $hGUIMain Then
                    If _IsChecked($ch_CloseMin) Then
                        ContinueCase
                    Else
                        _Exit()
                    EndIf
                ElseIf $aGM[1] = $hGUIOptions Then
                    GUISetState(@SW_HIDE, $hGUIOptions)
                    WinActivate($hGUIMain)
                EndIf
            Case $GUI_EVENT_MINIMIZE
                GUISetState(@SW_MINIMIZE, $hGUIMain)
                If _IsChecked($ch_MinToTray) Then
                    GUISetState(@SW_HIDE, $hGUIMain)
                    TraySetState($TRAY_ICONSTATE_SHOW)
                EndIf
            Case $GUI_EVENT_MOUSEMOVE
                ToolTip('')
        EndSwitch
    WEnd
EndFunc

Func _Exit()
    IniDelete($USER_FILE, 'Users', $USER_NAME)
    Exit
EndFunc

Func _EncodeMessage($sString)
    $sString = StringStripCR($sString)
    $sString = StringReplace($sString, '%', '%%')
    $sString = StringReplace($sString, '\', '\\')
    $sString = StringReplace($sString, @LF, '\n')
    $sString = StringReplace($sString, @TAB, '\t')
    Return $sString
EndFunc

Func _DecodeMessage($sString)
    $sString = StringFormat($sString)
    $sString = StringReplace($sString, '<', '<')
    $sString = StringReplace($sString, '>', '>')
    $sString = StringReplace($sString, @TAB, '    ')
    $sString = StringReplace($sString, @LF, '<br />' & @CRLF & '        ') ; Tabs for HTML indentation
    $sString = StringRegExpReplace($sString, '((?:file|https?)://\S+|\\\\\S+\\\S*)', _
        '<span class="link" onclick="document.getElementById(''autoit_monitor'').value=''URL:''+this.innerHTML">\1</span>')
    Return $sString
EndFunc

Func _SendChat($iCtrl)
    Local $sMessage = StringStripWS(GUICtrlRead($iCtrl), 3)
    If $sMessage Then
        FileWrite($CHAT_FILE, @CRLF & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @TAB & $USER_NAME & @TAB & _EncodeMessage($sMessage))
        _AddHistory($sMessage)
        GUICtrlSetData($iCtrl, '')
    EndIf
EndFunc

Func _LoadChat($iShowTimes)
    Local Enum $RE_DATETIME, $RE_USER, $RE_TEXT
    Local Enum $DT_DATE, $DT_TIME
    Local $sOutput, $sDateMem, $aLines, $iLineCount, $iLineTrack = 0, $aRegExLine, $aDateTime

    $sOutput = StringFormat('<html>\r\n<head>\r\n\t<link href="%s" rel="stylesheet">\r\n</head>\r\n', $CSS_FILE)
    $sOutput &= '<body onkeydown="document.getElementById(''autoit_monitor'').value=''KEY:''+event.keyCode">' & @CRLF
    $sOutput &= '<table>' & @CRLF

    $aLines = FileReadToArray($CHAT_FILE)
    $iLineCount = @extended
    For $L = 0 To $iLineCount-1
        If Not StringStripWS($aLines[$L], 3) Then ContinueLoop

        $aRegExLine = StringRegExp($aLines[$L], '(\d{14})\t(.+)\t(.+)', 1)
        If Not @error Then
            $aDateTime = _FormatTime($aRegExLine[$RE_DATETIME])
            If $aDateTime[$DT_DATE] <> $sDateMem Then
                $sOutput &= '<tr><td class="date" colspan="2">' & $aDateTime[$DT_DATE] & '</td></tr>' & @CRLF
                $sDateMem = $aDateTime[$DT_DATE]
                $iLineTrack = 0
            EndIf

            $sOutput &= '<tr class="rowOffset' & Mod($iLineTrack, 2) & ' user' & $aRegExLine[$RE_USER] & '">' & @CRLF
            $sOutput &= '   <td class="name_column">' & @CRLF
            If $iShowTimes Then $sOutput &= '       <span class="timestamp">[' & $aDateTime[$DT_TIME] & '] </span>' & @CRLF
            $sOutput &= '       <span class="username"><' & $aRegExLine[$RE_USER] & '></span> ' & @CRLF
            $sOutput &= '   </td>' & @CRLF
            $sOutput &= '   <td class="text_column">' & @CRLF
            $sOutput &= '       ' & _DecodeMessage($aRegExLine[$RE_TEXT]) & @CRLF
            $sOutput &= '   </td>' & @CRLF
            $sOutput &= '</tr>' & @CRLF
            $iLineTrack += 1
        EndIf
    Next
    $sOutput &= '</table>' & @CRLF
    $sOutput &= StringFormat('<input type="hidden" id="autoit_monitor" />\r\n</body>\r\n</html>')
    Return $sOutput
EndFunc

Func _FormatTime($sTime, $bToString = False)
    Local $aMonths = StringSplit('Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec', '|')
    Local $aRegEx = StringRegExp($sTime, '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})', 1)
    Local $aReturn[2]
    If Not @error Then
        $aReturn[0] = $aRegEx[0] &'-'& $aMonths[Int($aRegEx[1])] &'-'& $aRegEx[2]
        $aReturn[1] = $aRegEx[3] &':'& $aRegEx[4] &':'& $aRegEx[5]
    EndIf

    If $bToString Then Return $aReturn[0] &' '& $aReturn[1]
    Return $aReturn
EndFunc

Func _AddHistory($sMessage)
    Local Const $LIST = '0123456789'
    _SendHistory(0)
    $sMessage = _EncodeMessage($sMessage)

    Local $sKey, $sKeyList = $HISTORY_LIST[10]
    For $i = 0 To StringLen($sKeyList)-1
        If $sMessage = $HISTORY_LIST[$i] Then
            $HISTORY_LIST[10] = $i & StringReplace($sKeyList, String($i), '')
            Return
        EndIf
    Next

    Local $sNext = StringLeft(StringRegExpReplace($LIST, '[' & $sKeyList & ']', ''), 1)
    If Not $sNext Then
        $sNext = StringRight($sKeyList, 1)
        $sKeyList = StringTrimRight($sKeyList, 1)
    EndIf

    $HISTORY_LIST[10] = $sNext & $sKeyList
    $HISTORY_LIST[Int($sNext)] = $sMessage
EndFunc

Func _SendHistory($iDir = 0)
    Static $iPosition = 0

    Local $sKeyList = $HISTORY_LIST[10]
    Local $sKeyLen = StringLen($sKeyList)
    Local $sKey

    If $iDir < 0 Then
        $iPosition = $iPosition > 0 ? $iPosition - 1 : 0
    ElseIf $iDir > 0 Then
        $iPosition = $iPosition < $sKeyLen ? $iPosition + 1 : $sKeyLen
    Else
        $iPosition = 0
    EndIf

    $sKey = StringMid($sKeyList, $iPosition, 1)
    Return $sKey ? $HISTORY_LIST[Int($sKey)] : ''
EndFunc

Func _SetSetting($idCtrl, $sIniKey)
    Local $iSetting = 0
    If _IsChecked($idCtrl) Then $iSetting = 1
    IniWrite($INI_FILE, $INI_SECTION, $sIniKey, $iSetting)

    Return $iSetting
EndFunc

Func _IsChecked($idCtrl)
    Return BitAND(GUICtrlRead($idCtrl), $GUI_CHECKED)
EndFunc

Func _IsFocused($idCtrl)
    Return _WinAPI_GetFocus() = GUICtrlGetHandle($idCtrl)
EndFunc

Func _CSSFile($iForce = 0)
    Return FileInstall('NetworkChat.css', $CSS_FILE, $iForce)
EndFunc

Func WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam)
    Local $tMinMaxInfo = DllStructCreate('int;int;int;int;int;int;int;int;int;int', $lParam)
    If $hWnd = $GLOBAL_ARRAY[$GLOBAL_WIN] Then
        DllStructSetData($tMinMaxInfo, 7, 300); min width
        DllStructSetData($tMinMaxInfo, 8, 300); min height
        DllStructSetData($tMinMaxInfo, 9, @DesktopWidth); max width
        DllStructSetData($tMinMaxInfo, 10, @DesktopHeight); max height
        Return
    EndIf
EndFunc

Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam)
    If $hWnd = $GLOBAL_ARRAY[$GLOBAL_WIN] Then
        Local $aClient = WinGetClientSize($hWnd)
        If $GLOBAL_ARRAY[$GLOBAL_TOGGLE] Then
            GUICtrlSetPos($GLOBAL_ARRAY[$GLOBAL_EMBED], 0, 0, $aClient[0] - 100, $aClient[1] - 105)
        Else
            GUICtrlSetPos($GLOBAL_ARRAY[$GLOBAL_EMBED], 0, 0, $aClient[0], $aClient[1] - 105)
        EndIf
    EndIf
EndFunc

 

Edited by therks

Share this post


Link to post
Share on other sites

@therks, off course I am^_^. I tried also changing you code to met my desired but as of this moment, I think this is great. Thanks, appreciated so much:)....


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By AoRaToS
      I started working on this program in the summer of 2008 then I stopped cause I faced some problems I couldn't overcome back then. Now that I've practiced more and have become a better scripter/programmer I'm releasing the program to the public to get some opinions. I know it's not a new concept but it's the first program I started besides some small stuff I did just for practice! I won't post the source code yet because it's still under construction, although I'm sure I've posted early stages of the code with bugs in the past in some topic...
      What I wanted was a simple, small, serverless program that would work without installation cause I wanted it for where I work, so I ended up with this!
      I have attached some images of various versions, also visit the forum thread.
      The package includes s!mpL3 LAN Messenger and the full change log.
      Current version 2.9.9.1! [04/07/2019]
      Check the Change Log below!
       
       
      http://www.autoitscript.com/forum/index.php?showtopic=88782
       
       
       
      Read the license before using this software.
       
    • By AoRaToS
      s!mpL3 LAN Messenger as the name suggests is a messenger designed and developed to offer chat communication over Local Area Networks while being as simple to use as possible. This project started way back in 2008 with only basic functionality and is regularly updated with new features in order to make it more useful and user friendly. What I wanted was a simple, small, serverless program that would work without installation cause that was the ideal combination for my workplace back then, so I ended up with this!

      I have attached some images from various versions:
      Check the rest below! (from various versions)

      More than 10.000 downloads!

      s!mpL3 LAN Messenger version 2.9.9.1 - [04/07/2019] - s!mpL3 LAN Messenger.zip
      1. Fixed an issue that would occur when blocking another user and they would re-appear in the TreeView.
      2. Updated File Transfers to make long file names shorter if they were too long to appear in the tray tip.
      3. Removed notifications when checking for updates at application startup if there is no update available.
      You can view/download the full change log here: ChangeLog.txt

      Tested and working on both 32bit and 64 bit editions of Windows XP, Windows Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10.


      Things you need to know before trying it:

      1. Start the program, select one or more connections from what's available and click Connect (If a firewall notice comes up, click 'Allow' or 'Add Exception')
      When someone else on your network does the same, they will appear in your Tree-view and you will appear in theirs, double click their name and chat!

      2. s!mpL3 LAN Messenger does not require a server to be running, it's standalone.

      3. On the first run an .ini file is created at @LocalAppDataDir\s!mpL3 LAN Messenger which stores the settings so that they are used every time you run the application. If you delete the .ini file it will be created again (with default settings at program startup or with your selected settings if you press Save from the Preferences window).

      4. All communication is encrypted using AES so it's quite secure against Network sniffers.

      5. You can send files and folders by dragging and dropping them in a conversation window. Folders are compressed before being sent. You can also drop multiple items to be sent.

      6. There is a "Hide" button located in the tray right click context menu that will hide all open windows. You can assign a Hotkey combination from Preferences. The default combination is Ctrl+H.

      7. s!mpL3 LAN Messenger uses port 60000 by default. You can change the port used by adding "Port=****" (without quotes, stars represent numbers) to the Config file described above. Communication is UDP.

      8. There is an Updater feature you can use to always have the latest available version, you only need an internet connection for that to work. You might need to clear your Internet Explorer Temporary Files in order for it to find an updated version.

      9. You can Hide + Lock s!mpL3 LAN Messenger so it'll require a password in order to "Appear". To enable this, go to the Security Preferences.

      10. Note that versions after 2.9.8.1 are not compatible with previous versions due to the encryption used being changed. I recommend using the latest version, or at least use the same version over the LAN.


      Important Notice:

      I will not be releasing the source code, however, I might share some parts of code if requested...
      If you choose to de-compile this software, don't release the source code.




    • By rcmaehl
      A UDF to connect to IRC using TCP Functions, as well as perform actions once connected.
      WANTED: Technical Writer able to create / maintain a helpfile (.chm) using the Autoit helpfile layout for an negotiated rate.

      Notes:
      Originally created by Chip.
      UDF Headers updated compared to old script.
      Error and Parameter Handling updated compared to old script.
      If you need to bypass the RFC compliance of this UDF, use _IRCRaw.
      The majority of the old functions have been modified. It will break most, if not all, scripts using the old UDF.
      These commands should work on every server following either RFC 1459 (legacy) or RFC 2812 (preferred).
       
      Potential Uses:
      IRC Chat Clients
      Chatroom Integration for software
      IRC Bots for Channel / Server Administration
      IRC Bots for Games such as Hangman, Mafia, and WereWolf
      Remote Administration without having to setup your own AutoIt server


      Functions:
      _IRCChannelInvite
      _IRCChannelJoin
      _IRCChannelKick
      _IRCChannelPart
      _IRCChannelTopic
      _IRCConnect
      _IRCDisconnect
      _IRCGetMsg
      _IRCMultiMode
      _IRCMultiSendMsg
      _IRCRaw
      _IRCSelfOper
      _IRCSelfSetNick
      _IRCSelfSetStatus
      _IRCServerPing
      _IRCServerPong
      _IRCServerTime
      _IRCServerVersion
       
      Extra Functions:
      _IRCReplyTo (IRCExtras.au3)
      _IRCStripSpecial (IRCExtras.au3)
       
      Downloads:
       
      Additional Links:
      Chips' Old UDF Topic:

       
      DISCLAIMER:
      While these downloads are more stable than the ones above, I do not have time to thoroughly test all functions and variable entries. If something doesn't work as expected or gives you an error please check @error and @extended variables then create a reply to this topic.

      Changelog:
      09/06/2016: IRC.au3 Fixed : Updated Headers to UDF-spec (- instead of =) _IRCGetMsg Fixed : Incorrect Return Value On Error _IRCStripSpecial Added : Better documentation of Flags _IRCMultiSendMsg Added : Better documentation of Flags _IRCMultiSendMsg Fixed : Max Message Size based on https://forums.unrealircd.org/viewtopic.php?t=6811 Updated all files to consider themselves a standalone install by default All Functions that didn't Return anything now return Number of bytes sent Slight Performance Improvements by using Parameter Gating instead of Single Input Single Output 07/21/2016: Example.au3 Fixed : Includes Example.au3 Renamed: IRC_Example.au3 IRC.au3 Changed: Minor Performance Improvements 04/18/2016: IRCConstants.au3 Updated: A Ton of New Constants added IRCMultiSendMsg Added : Color Example Increased TCP Timeout in all Examples 04/13/2016: CUI.au3 Updated: Errors now output to Error Stream in Console (C/G)UI.au3 Fixed : Userlists (FOR REAL THIS TIME) by being sure to get the current channel Removed: Duplicate Constants File Include Removed: Local Declaration inside of While loop for Performance Updated: TCPTimeout Increased Updated: $sTemp renamed $sStrip for Readibility Example.au3 Updated: TCPTimeout Increased GUI_Client.au3 Renamed: GUI.au3 _IRCStripSpecial Added : Parameter Checking Updated: Documentation _IRCMultiSendMsg Added : Additional flags for Message Type (POSSIBLY SCRIPT BREAKING if using $_bTrim!) Updated: Example to show new flags Updated: Increase Max Message Size from 368 To 436 04/09/2016: IRC.au3 Updated: All Documentation Added : Now has a Constaznts file _IRCConnnect Fixed : Now PROPERLY returns any errors _IRCGetMsg Removed: $_iChars parameter since it gets one packet at a time and parsing is easier _IRCReplyTo Fixed : Now properly returns username _IRCStripSpecial Added : Now uses Constants File All files are now in a single ZIP Includes 2 basic IRC "clients", a CUI, and a GUI 07/15/2015: Example.au3 Added : Improved Debugging   Updated: All Space Indents to Tab Idents   IRC.au3 Removed: Exception skipping @error = -1 in IRCGetMsg() as 3.3.14.0 fixed it 07/15/2015: Example.au3 Added : Ping Timeout Fixed : Userlist clipping of last user IRC.au3 Fixed : IRCGetMsg() Hang 07/08/2015: Example.au3 Fixed : User Lists   Fixed : Nickname now switches to backup nickname if first choice is already in use IRC.au3 Added : UDF Index Added : #include-once Updated: All Functions updated to Single Entry, Single Exit Updated: Now passes Au3Check on -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 01/15/2015: Example.au3 Fixed : Ampersand channels causing a crash 12/20/2014: Example.au3 Fixed : Nicks not updating on all channel lists when a user changed their nick Fixed : Nicks not deleting on all channel lists when a user quits the network 12/19/2014: Example.au3 Added : User lists Added : Channel lists Added : Bot keeps track of own nick Added : Secondary nick in case first nick choice is in use. Added : Extremely Minor performance improvements _IRCConnect Added : Improved parameter checking _IRCGetMsg Updated: Now only retrieves one packet by default (MAY be script breaking) 10/14/2014: Example.au3 Added : Shutdown TCP on exit Fixed : $Recipient now gets the actual Recipient instead of the 3rd message Added : Now exits when told to quit. IRC.au3 Added : Improved Error Reporting (Includes @extended on error) _IRCDisconnect Added : Close Socket on Disconnect _IRCStripSpecial Added : Improved Color Stripping 09/28/2014: _IRCConnect Fixed : Checking if Mode was blank. _IRCGetMsg Fixed : Spamming of 0 and incorrectly thinking there was an error. 09/28/2014: IRC.au3 Fixed : All functions now return when errors are encountered instead of continuing _IRCConnect Added : Now returns an error if optional password failed to send _IRCGetMsg Added : Now returns an error if it failed to receive a custom amount of data _IRCServerVersion Fixed : Capitalized "Version" 09/26/2014: Example.au3 Fixed : Pings not ending with @CRLF IRCExtras.au3 Added : _IRCStripSpecial(), Cleans special characters sometimes seen in IRC 09/24/2014: Example.au3 Added : Checking for PrivMsg Fixed : Infinite loop if you removed _IRCDisconnect Updated: Bot now disconnects when receiving "!quit" instead of automatically Discontinuted BETA UDF project. 04/20/2014: IRCExtras.au3 Added : Additional IRC Functions _IRChangeNick Renamed: _IRCSelfSetNick (SCRIPT BREAKING! Fix: Replace _IRCChangeNick with _IRCSelfSetNick) _IRCGetMsg Fixed : Now no longer Splits Packets if Default option is used _IRCChannelInvite Added : Invites a User to a Channel _IRCChannelKick Added : Kick a User from a channel _IRCJoinChannel Renamed: _IRCChannelJoin (SCRIPT BREAKING! Fix: Replace _IRCJoinChannel with _IRCChannelJoin) _IRCMode Renamed: _IRCMultiMode (SCRIPT BREAKING! Fix: Replace _IRCMode with _IRCMultiMode) _IRCOper Renamed: _IRCSelfOper (SCRIPT BREAKING! Fix: Replace _IRCOper with _IRCSelfOper) _IRCPartChannel Renamed: _IRCChannelPart (SCRIPT BREAKING! Fix: Replace _IRCPartChannel with _IRCChannelPart) _IRCPing Renamed: _IRCServerPing (SCRIPT BREAKING! Fix: Replace _IRCPing with _IRCServerPing) _IRCPong Renamed: _IRCServerPong (SCRIPT BREAKING! Fix: Replace _IRCPong with _IRCServerPong) _IRCSelfSetStatus Added : Sets you AFK and un-AFK _IRCSendMessage Renamed: Renamed _IRCMultiSendMsg. (SCRIPT BREAKING Fix: Replace IRCSendMessage with IRCMultiSendMsg) _IRCSendMessageRaw Renamed: Renamed _IRCRaw (SCRIPT BREAKING! Fix: Replace _IRCSendMessageRaw with _IRCRaw) _IRCServerTime Added : Get time from a Server _IRCServerVersion Added : Get Software Version from a Server _IRCTopic Renamed: _IRCChannelTopic (SCRIPT BREAKING! Fix: Replace _IRCTopic with _IRCChannelTopic) Improved Parameter detection in all Functions Renamed Functions to show who/what they effect, MASSIVE Script Breaking. Sorry! :/ 04/06/2014: _IRCGetMsg Added : Use to get IRC Messages. _IRCSetTopic Changed: Now named _IRCTopic (SCRIPT BREAKING! Fix: Replace _IRCSetTopic with _IRCTopic) Changed: Can now be used to query topic and does so by default. Use "" to blank the topic All functions now thoroughly check their parameters Updated all functions to use @extended to some errors Fixed @error returning 0 by starting all errors at 1 instead of 0 03/20/2014: _IRCChangeMode Changed: Now named _IRCMode (SCRIPT BREAKING! Fix: Replace _IRCChangeMode with _IRCMode) Changed: $_sMode is now OPTIONAL. Allowing the command to be used to Query current mode as well _IRCConnect Fixed : Missing Colon Before $_sRealName. It should now allow Real Names with spaces _IRCDisconnect Fixed : Issue with Blank Messages. Should now properly blank to Default _IRCPing Changed: $_Server is now REQUIRED. (SCRIPT BREAKING! Fix: Specify a server as Parameter 2) _IRCSendMessage Added : $_bTrim, Trims message if too long instead of breaking up the message, Default is true _IRCSetTopic Added : Command for setting a Channel Topic Updated Most Functions to include better error checking Updated Most Channel Related Functions to check for valid channels 03/16/2014: _IRCChangeMode Added : Optional parameters for channel modes Changed: Parameter ordering Target is now before Mode (SCRIPT BREAKING! Fix: Swap Parameters 2 and 3) _IRCConnect Changed: No longer exits the script on error, instead returns TCPConnect Error Code _IRCJoinChannel Added : Now Supports Channel Passwords _IRCOper Added : Command for IRC Server Operator Login Updated All Functions to have UDF standard error codes 02/24/2014: _IRCSendMessage Changed: Split Into _IRCSendMessage and _IRCSendMessageRaw (SCRIPT BREAKING! No Simple Fix Available) 02/23/2014: Made variables comply to UDF Standards http://www.autoitscript.com/autoit3/udfs/UDF_Standards.htm Removed MsgBoxes left over from old UDF Updated / Uploaded IRC.au3 Known and Reported Bugs:
      Message output only displays ANSI characters in CUI. (Can't Fix) Freenode requires registration for part messages thus the part message in example doesn't show up (Can't fix) Messages (e.g. PRIVMSG) are not forwarded?, when it contains umlauts/german mutations and when the message only contains a dot '.' (Unconfirmed) Warnings:
      Do NOT send a lot of messages at once. MOST networks will disconnect you. SOME networks will permanently ban you. A MINORITY will harshly retailiate. Do NOT use the Sleep() function in your scripts. It prevents you from receiving any new data, can disconnect your from the network, and have other undesired consequences. Use the TimerInit() and TimerDiff() functions and possibly a message queue. To Do:
      Possibly add in SSL functionality Create More Functions for IRC commands An entire IRC daemon written in AutoIt Possibly Include Kips TCP UDF for ASync Port Listening in Example Create Additional UDFs for extras such as CTCP, DCC, and Error Lookup Experiment with having functions check for the reply and see if reliable. Upcoming Changes:
      To Be Decided
    • By Cormin
      My script currently reads a text file line by line. I want it to look for this the chat message below and skip the session messages. 
      There are some garbage lines that I want it to skip over. So if a line doesnt match that format then skip it. I tried experimenting with StringRegExp but I think I'm using it wrong. Heres my code
      If StringRegExp($read, '\W\d\d\w\d\d\D.\W') = Not @error Then I was hoping that this would be able to see the open bracket, 2 digits, a colon, 2 digits,  close bracket, a space and a <. But it doesn't seem to be working.
       
      Eventually I want to be able to extract the username and chat message into separate strings but I haven't got that far yet.
    • By Messy_Code_Guy
      All,
      I need some help with the following:
      1. Finding an image in a Word doc.  I have read the help file but I cannot figure out how to reference the image in the Word doc.
      2. Adding a hyperlink to that image.
      3. How would I loop the add hyperlink (text) and add hyperlink (image) to replace multiple links in a document.
      I have the add image and hyperlink working with the following code:
      $pic = "<PHOTO>" $picpath = IniRead(@ScriptDir & "\Config\Config.ini", "User Info", "Picture", 0) Local $oRange = _Word_DocFind($oDoc, $pic) _Word_DocPictureAdd($oDoc, $picpath, Default, Default, $oRange) _Word_DocFindReplace($oDoc, $pic, "", Default, 0, True, True) If @error Then $file1 = FileOpen("C:\Tech\Log_Files\_Error_Logs\Error_LOG.txt", 9) _FileWriteLog($file1, "," & @ComputerName & "," & @UserName & ",Error adding a picture to the document. " & $picpath & " " & " @error = " & @error & " @extended = " & @extended) FileClose($file1) EndIf $Link = "<LINKEDIN>" $LinkedIn = IniRead(@ScriptDir & "\Config\Config.ini", "User Info", "LinkedIn", 0) Local $oRange = _Word_DocFind($oDoc, $Link) _Word_DocLinkAdd($oDoc, $oRange, $LinkedIn, Default, "Click here to visit my LinkedIn page. " & @CRLF & $LinkedIn, "LinkedIn") If @error Then $file1 = FileOpen("C:\Tech\Log_Files\_Error_Logs\Error_LOG.txt", 9) _FileWriteLog($file1, "," & @ComputerName & "," & @UserName & ",Error adding a link to the document. " & $LinkedIn & " " & " @error = " & @error & " @extended = " & @extended) FileClose($file1) EndIf I just can't figure out how to find the images in a Word doc.
      Thanks for reading my post!
×
×
  • Create New...