Jump to content

Simple "chat" program with clickable links


therks
 Share

Recommended Posts

Hi there,

So I've created this very simple "chat" program so that my brother and I can quickly and easily share text and links to other computers on the network. It just reads/writes to a text file that the script interprets/formats appropriately. I will put the script it in a shared network folder and then any of the computers can open and use it.

For displaying the "chat" I'm currently using an embedded IE browser and formatting the text via HTML, but I've realized that this will cause problems with opening the links because it will use IE instead of the system's default browser (Chrome in our case). Any suggestions? (To be clear, I'm specifically looking for assistance on having text with clickable links that will open in the default browser.)

 

For anyone interested, here's the code so far:

#include <GUIConstants.au3>
#include <GUIEdit.au3>
#include <IE.au3>

Opt('TrayIconDebug', 1)

Global $CHAT_FILE = @ScriptDir & '\NetworkChat.txt'

Main()

Func Main()
    Local $hGUIMain = GUICreate('Network Chat', 500, 500, 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, 370, 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, 370, 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, 390, 215, 20)
        GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))

    Local $aAccel = [ _
        [ '{enter}', $dm_AccelEnter ], _
        [ '+{enter}', $dm_AccelShiftEnter ], _
        [ '{tab}', $dm_AccelTab ], _
        [ '{pgup}', $dm_AccelPgUp ], _
        [ '{pgdn}', $dm_AccelPgDn ], _
        [ '^a', $dm_AccelCtrlA ] ]
    Local $aAccelSwap = $aAccel
    $aAccelSwap[0][0] = '+{enter}'
    $aAccelSwap[1][0] = '{enter}'

    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

        Local $iMsg = GUIGetMsg()
        If $iMsg > 0 Then ConsoleWrite($iMsg & @CRLF)
        Switch $iMsg
            Case $ch_Timestamps
                $aChatTime[1] = 0
            Case $ra_Enter
                GUISetAccelerators($aAccel)
            Case $ra_ShiftEnter
                GUISetAccelerators($aAccelSwap)
            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
                If $hFocused = GUICtrlGetHandle($ed_Chat) Then
                    _SendChat($ed_Chat)
                Else
                    GUICtrlSetState($ed_Chat, $GUI_FOCUS)
                EndIf
            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
                ExitLoop
        EndSwitch
    WEnd
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, '<', '<')
    $sString = StringReplace($sString, '>', '>')
    $sString = StringFormat($sString)
    $sString = StringReplace($sString, @TAB, '    ')
    $sString = StringReplace($sString, @LF, '<br />')
    $sString = StringRegExpReplace($sString, '(http://\S+)', '<a href="\1" target="_blank">\1</a>')
    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>'
    $sOutput &= 'body, table { margin: 0; font-family: Arial; font-size: 0.8em; border-collapse: collapse; width: 100%; } '
    $sOutput &= 'tr { vertical-align: top; text-align: left; } '
    $sOutput &= '.name_column { white-space: nowrap; } '
    $sOutput &= '.text_column { width: 100%; } '
    $sOutput &= '.row1 { background: #eee; } '
    $sOutput &= '.date { background: #bef; text-align: center; border: solid #000; border-width: 1px 0; } '
    If Not $iShowTS Then $sOutput &= '.timestamp { display: none }'
    $sOutput &= '</style>'
    $sOutput &= '<table>'

    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) & '" title="' & $aDateTime[1] & '">' & _
                '<th class="name_column"><span class="timestamp">[' & $aDateTime[1] & '] </span>' & $aRegExLine[1] & '</th>' & _
                '<td class="text_column">' & _EncodeFromFile($aRegExLine[2]) & '</td></tr>' & @CRLF
        EndIf
    Next
    $sOutput &= '</table>'
    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

QrITWa6.png

 

Edited by therks
Link to comment
Share on other sites

Maybe I wasn't clear, but that doesn't have clickable links either which is the issue I'm looking for a solution for.

Also, I did search the forum. Found this post: 

But there's no script to be seen. It looks like maybe Jon removed it back in 2012?

Edited by therks
Link to comment
Share on other sites

In reference to your first post, I saw nothing in there that will help me achieve what I'm looking for sadly. I'm looking at the RichEdit control now, but it's going off the rails very quickly. Not being a standard AutoIt control there's a lot I would have to handle manually. Also it seems the URL detecting doesn't work properly for 32 bit (at least the example for _GUICtrlRichEdit_AutoDetectURL doesn't work).

Concerning that last one, that wiki entry just links back to the same topic I linked to (with the missing script). But yes, that seems to be right on track with what I'd like to do.

Edited by therks
Link to comment
Share on other sites

nope, you were right on. so, what about we make a function that can determine the default browser and embed the appropriate browser in your gui? we can do that for chrome, can we not? i could be off base here, I am not a gui guy, sorry. I rarely deal with this stuff, if ever. I'm mostly build and testing.

this will tell you what the default is set to.

$myDefaultBrowser = RegRead("HKEY_CURRENT_USER\Software\Clients\StartMenuInternet", "")

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Hmm, I don't think Chrome can be embedded. When I looked around it seemed it could only be IE as it's so ingrained with the OS, but I'd love to proven wrong. :)

What I'd really like is to know how Gary's UDF worked back in the day. That image on the wiki is such a tease.

Edited by therks
Link to comment
Share on other sites

oooh! oooh!! how about this. it work in a message box, why not a rich edit control! i just tested with latest AutoIt, works.

#NoTrayIcon
#include <Constants.au3>
#include <GUIConstants.au3>

Opt("GUICloseOnESC",1)
Opt("GUIOnEventMode",1)

$about = GuiCreate("About",215,150,-1,-1,BitOR($WS_CAPTION,$WS_SYSMENU))
GUISetOnEvent ($GUI_EVENT_CLOSE, "AboutOK" )
GUICtrlCreateIcon (@AutoItExe,-1,11,11)
GUICtrlCreateLabel ("App name 1.0",59,11,135,20)
GUICtrlSetFont (-1,10, 800, 0, "Arial"); bold
GUICtrlCreateLabel ("(c) 2005" & @CRLF & @CRLF & "Zedna",59,30,135,40)
$email = GUICtrlCreateLabel ("author@somewhere.com",59,70,135,15)
GuiCtrlSetFont($email, 8.5, -1, 4); underlined
GuiCtrlSetColor($email,0x0000ff)
GuiCtrlSetCursor($email,0)
GUICtrlSetOnEvent(-1, "OnEmail")
$www = GUICtrlCreateLabel ("www.autoitscript.com/forum/",59,85,140,15)
GuiCtrlSetFont($www, 8.5, -1, 4); underlined
GuiCtrlSetColor($www,0x0000ff)
GuiCtrlSetCursor($www,0)
GUICtrlSetOnEvent(-1, "OnWWW")
GUICtrlCreateButton ("OK",65,115,75,23,BitOr($GUI_SS_DEFAULT_BUTTON, $BS_DEFPUSHBUTTON))
GUICtrlSetState (-1, $GUI_FOCUS)
GUICtrlSetOnEvent(-1, "AboutOK")
GUISetState(@SW_SHOW, $about)

While 1
    Sleep(100)
WEnd

Func OnEmail()
    Run(@ComSpec & " /c " & 'start mailto:author@somewhere.com?subject=Something', "", @SW_HIDE)
EndFunc

Func OnWWW()
    Run(@ComSpec & " /c " & 'start www.autoitscript.com/forum/', "", @SW_HIDE)
EndFunc

Func AboutOK()
    Exit
EndFunc

Func OnAutoItExit()
    GUIDelete($about)
EndFunc

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Yeah I've done something like that before, but it won't work here. That's making a label look like a link and then just handling the notification, basically like a button or other notifying control. I can't think of a way to embed something like that within normal text. If I could somehow get the embedded browser to pass the notification of a clicked link back to the AutoIt script I could handle it like that... but.. I just came up with an idea actually.

Link to comment
Share on other sites

Oh for sure. It's working. Just wanted to test it first. It's kind of hacky cus it's not just AutoIt it uses JavaScript too.

So basically it goes like this. Instead of actually using links (<a href="">) in the HTML, I'm wrapping the URLs in <span> tags, styled to look like links. When clicking on the <span>, they set a <div> element's innerText to the URL from the span. The AutoIt script is constantly monitoring the <div> tag for changes and when it detects a change, it reads the content and then ShellExecute's it.

Link to comment
Share on other sites

Turns out that UDF was for naught as it doesn't work the way I hoped it would. However, I've been having a great deal of success with the method I figured out above. This is still a work in progress, but here's what I have so far.

#include <GUIConstants.au3>
#include <GUIEdit.au3>
#include <IE.au3>
#include <GuiRichEdit.au3>
;~ #include <Variable.au3>

Opt('TrayIconDebug', 1)

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

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

Main()

Func Main()
    Local $hGUIMain = GUICreate('Network Chat', 500, 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 $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
                ExitLoop
        EndSwitch
    WEnd
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
Link to comment
Share on other sites

Hi @therks,

Thanks for the code you have, I used it and very satisfied with the outcome also it was perfect for my project and everything is good. However, is there a way that your code can be modify that who ever runs the program it will create label somewhere in the GUI that "@username is active".

I would like to see who is using the program and I need to know the username of that user.^_^ Thanks if that would be fine with you.:sweating:

 

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.

Link to comment
Share on other sites

It would take a significant modification to do that. Currently this is really nothing more than a front end for reading/writing a fancy log file.

To monitor users that are "online" so to speak it would have to record when a user opens the program, remove them when the program closes, and in case the program crashes it would have to ping active users.

You're welcome to modify it however you see fit, but for me currently it's doing what I need. :)

Link to comment
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
 Share

×
×
  • Create New...