Sign in to follow this  
Followers 0
Altalus

Help With Lazycat Richtext Code Please

18 posts in this topic

Hi, sooooo sorry to bother you guys but... I'm trying to use the functions and DLL Lazycat provided for Richtext.

So far It looks VERY good. However I might be try to do something impossible... here's the thing.

Building Chat like apps. I need to add text at the end of the box. Howerver the function

GUICtrlRTFSet(RTF_control_handle, RTF_string[, type])
only allow you to either replace all or add at the cursor position.

I don't trust my users, they WILL click anywhere in the box to copy/paste things...

So I tried to

GUICtrlRTFGet(RTF_control_handle)
the text already in the box, then to
_RTFAppendString(...)
the new text... doesn't seem to work. See the code below.

Is there an eisier way ? Maybe to tell the cursor at the end of the text and THEN add the new one ?

Thanks in advance !

$try = GUICtrlRTFGet($hEdit)
        ;Msgbox (0,"Debug",$try)
            $temp = ""
            $temp = _RTFCreateDocument("MS Sans Serif")
            $temp = _RTFAppendString($try, " Current system time: " & @HOUR & ":"& @MIN &":"& @SEC &@CRLF, 0xFF0000, 10, 1, "MS Sans Serif")
        ;Msgbox (0,"Debug",$try)
            Msgbox (0,"Debug",$temp)
            GUICtrlRTFSet($hEdit, $temp, 0)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

_PutNormalText($send_box, "Type your text here", 0x000000)

Func _PutNormalText(ByRef $hEdit, $sText, $hex_color, $b_Append = 1)
 Local $out = _RTFCreateDocument("MS Sans Serif")
 $out = _RTFAppendString($out, $sText & @CRLF, $hex_color, 8, 1, "MS Sans Serif")
 GUICtrlRTFSet ($hEdit, $out, $b_Append)
 Sleep(100)
EndFunc;==>_PutNormalText

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

_PutNormalText($send_box, "Type your text here", 0x000000)

Func _PutNormalText(ByRef $hEdit, $sText, $hex_color, $b_Append = 1)
 Local $out = _RTFCreateDocument("MS Sans Serif")
 $out = _RTFAppendString($out, $sText & @CRLF, $hex_color, 8, 1, "MS Sans Serif")
 GUICtrlRTFSet ($hEdit, $out, $b_Append)
 Sleep(100)
EndFunc;==>_PutNormalText
Thanks for the answer but the behavior is the same :)

As I said, I don't thrust my user... Try to use your function after clicking in the middle of the box. It will insert the new text where the cursor is. The window is Read-only but the user should be able to copytext out of it. Now I need a way to add new text, but always at the end of the current text in the box, even if the user already clicked elsewhere in the said box.

Sorry :">

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks for the answer but the behavior is the same :)

As I said, I don't thrust my user... Try to use your function after clicking in the middle of the box. It will insert the new text where the cursor is. The window is Read-only but the user should be able to copytext out of it. Now I need a way to add new text, but always at the end of the current text in the box, even if the user already clicked elsewhere in the said box.

Sorry '>

try (requires beta and #include <GuiEdit.au3>)

_PutNormalText($send_box, "Type your text here", 0x000000)

Func _PutNormalText(ByRef $hEdit, $sText, $hex_color, $b_Append = 1)
    Local $out = _RTFCreateDocument("MS Sans Serif")
    $out = _RTFAppendString($out, $sText & @CRLF, $hex_color, 8, 1, "MS Sans Serif")
    _GUICtrlEditSetSel ($hEdit, StringLen(GUICtrlRead($hEdit)), StringLen(GUICtrlRead($hEdit)))
    GUICtrlRTFSet ($hEdit, $out, $b_Append)
    Sleep(100)
EndFunc;==>_PutNormalText
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

try (requires beta and #include <GuiEdit.au3>)

_PutNormalText($send_box, "Type your text here", 0x000000)

Func _PutNormalText(ByRef $hEdit, $sText, $hex_color, $b_Append = 1)
    Local $out = _RTFCreateDocument("MS Sans Serif")
    $out = _RTFAppendString($out, $sText & @CRLF, $hex_color, 8, 1, "MS Sans Serif")
    _GUICtrlEditSetSel ($hEdit, StringLen(GUICtrlRead($hEdit)), StringLen(GUICtrlRead($hEdit)))
    GUICtrlRTFSet ($hEdit, $out, $b_Append)
    Sleep(100)
EndFunc;==>_PutNormalText
Closer :)

Here is the output when I click the button:

CTesting
lick "Time" button to get system time...

Somehow it doesn't go to the end of it but at the 2nd position... I tried to click elsewhere in the box, just-in-case, but the behavior stay the same... hmmm...

I'll attach the entire code in case it can help.

Almost there ! :mellow:

test_plugin.au3

Share this post


Link to post
Share on other sites

_GUICtrlEditSetSel ($hEdit, StringLen(GUICtrlRTFGet($hEdit)), StringLen(GUICtrlRTFGet($hEdit)))


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

_GUICtrlEditSetSel ($hEdit, StringLen(GUICtrlRTFGet($hEdit)), StringLen(GUICtrlRTFGet($hEdit)))
PERFECT ! :mellow:

Thank you very much gafrost :)

Share this post


Link to post
Share on other sites

Hummm and I tought everything was perfect :)

Another problem, the program will eithe freeze or simply close totally randomly...

I've attached the program again (with the modifications) and here is the output of the debug file. Any idea ??? DLL problem ? Something else ?

2006-03-16 17h 42:04 Starting the Apps
2006-03-16 17h 42:04 Included needed files
2006-03-16 17h 42:04 PluginOpen rtfplugin.dll
2006-03-16 17h 42:04 TCPStartup()
2006-03-16 17h 42:08 Openning socket
2006-03-16 17h 42:08 Socket openned
2006-03-16 17h 42:08 Creating GUI
2006-03-16 17h 42:08 GUI created
2006-03-16 17h 42:08 Soon in the main loop
2006-03-16 17h 42:08 Received #ACKCONNECTION
2006-03-16 17h 42:08 Received #BROADCAST
2006-03-16 17h 42:08 writeToScreen()
2006-03-16 17h 42:08 Local $out = _RTFCreateDocument($font_name)
2006-03-16 17h 42:08 $out = _RTFAppendString($out, $text & @CRLF, $hex_color, $font_size, $font_style, $font_name)
2006-03-16 17h 42:08 _GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
2006-03-16 17h 42:08 GUICtrlRTFSet ($edit, $out, 1)
2006-03-16 17h 42:11 User Pressed SEND
2006-03-16 17h 42:11 Typed: #CHATSAY
2006-03-16 17h 42:11 Received #CHATSAY
2006-03-16 17h 42:11 writeToScreen()
2006-03-16 17h 42:11 Local $out = _RTFCreateDocument($font_name)
2006-03-16 17h 42:11 $out = _RTFAppendString($out, $text & @CRLF, $hex_color, $font_size, $font_style, $font_name)
2006-03-16 17h 42:11 _GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
2006-03-16 17h 42:11 GUICtrlRTFSet ($edit, $out, 1)
2006-03-16 17h 42:11 PlayWarning()
2006-03-16 17h 42:14 User Pressed SEND
2006-03-16 17h 42:14 Typed: #CHATSAY
2006-03-16 17h 42:14 Received #CHATSAY
2006-03-16 17h 42:14 writeToScreen()
2006-03-16 17h 42:14 Local $out = _RTFCreateDocument($font_name)
2006-03-16 17h 42:14 $out = _RTFAppendString($out, $text & @CRLF, $hex_color, $font_size, $font_style, $font_name)
2006-03-16 17h 42:14 _GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
2006-03-16 17h 42:14 GUICtrlRTFSet ($edit, $out, 1)

client.au3

Share this post


Link to post
Share on other sites

might want to provide the server side.

Np, here is the code for the Server.

server.au3

Share this post


Link to post
Share on other sites

I'm not having those problems

compiled with ver 3.1.1.113

running the server and 2 chat clients

no freezes or abnormal app closing.

Been running and sending text back and forth no problems for about 15 minutes.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I'm not having those problems

compiled with ver 3.1.1.113

running the server and 2 chat clients

no freezes or abnormal app closing.

Been running and sending text back and forth no problems for about 15 minutes.

I was using v3.1.1.106... I'll download the new version and give you news...

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I was using v3.1.1.106... I'll download the new version and give you news...

Hummm... same problems... And even worst now it seem... lemme check the logs...

2006-03-16 20h01:01 Starting the Apps
2006-03-16 20h01:01 Included needed files
2006-03-16 20h01:01 PluginOpen rtfplugin.dll
2006-03-16 20h01:01 TCPStartup()
2006-03-16 20h01:03 Openning socket
2006-03-16 20h01:03 Socket openned
2006-03-16 20h01:03 Creating GUI
2006-03-16 20h01:03 GUI created
2006-03-16 20h01:03 Soon in the main loop
2006-03-16 20h01:03 Received #ACKCONNECTION
2006-03-16 20h01:03 Received #BROADCAST
2006-03-16 20h01:03 writeToScreen()
2006-03-16 20h01:03 Local $out = _RTFCreateDocument($font_name)
2006-03-16 20h01:03 $out = _RTFAppendString($out, $text & @CRLF, $hex_color, $font_size, $font_style, $font_name)
2006-03-16 20h01:03 _GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
2006-03-16 20h01:03 GUICtrlRTFSet ($edit, $out, 1)
2006-03-16 20h01:06 User Pressed SEND
2006-03-16 20h01:06 Typed: #CHATSAY
2006-03-16 20h01:06 Received #CHATSAY
2006-03-16 20h01:06 writeToScreen()
2006-03-16 20h01:06 Local $out = _RTFCreateDocument($font_name)
2006-03-16 20h01:06 $out = _RTFAppendString($out, $text & @CRLF, $hex_color, $font_size, $font_style, $font_name)
2006-03-16 20h01:06 _GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
2006-03-16 20h01:06 GUICtrlRTFSet ($edit, $out, 1)
2006-03-16 20h01:07 PlayWarning()
2006-03-16 20h01:07 User Pressed SEND
2006-03-16 20h01:07 Typed: #CHATSAY
2006-03-16 20h01:07 Received #CHATSAY
2006-03-16 20h01:07 writeToScreen()
2006-03-16 20h01:07 Local $out = _RTFCreateDocument($font_name)
2006-03-16 20h01:07 $out = _RTFAppendString($out, $text & @CRLF, $hex_color, $font_size, $font_style, $font_name)
2006-03-16 20h01:07 _GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
2006-03-16 20h01:07 GUICtrlRTFSet ($edit, $out, 1)

Hmmm it always crash (on my system anyway) when it's calling a func in the DLL to write infos to the screen...

Trying to add a sleep in case the DLL was "slow" (bah, trying :) )

_GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
writeDebug("GUICtrlRTFSet ($edit, $out, 1)")
sleep(100)
GUICtrlRTFSet ($edit, $out, 1)

Nope... still freezing...

2006-03-16 20h05:20 Starting the Apps
2006-03-16 20h05:20 Included needed files
2006-03-16 20h05:20 PluginOpen rtfplugin.dll
2006-03-16 20h05:20 TCPStartup()
2006-03-16 20h05:28 Openning socket
2006-03-16 20h05:28 Socket openned
2006-03-16 20h05:28 Creating GUI
2006-03-16 20h05:28 GUI created
2006-03-16 20h05:28 Soon in the main loop
2006-03-16 20h05:28 Received #ACKCONNECTION
2006-03-16 20h05:28 Received #BROADCAST
2006-03-16 20h05:28 writeToScreen()
2006-03-16 20h05:28 Local $out = _RTFCreateDocument($font_name)
2006-03-16 20h05:28 $out = _RTFAppendString($out, $text & @CRLF, $hex_color, $font_size, $font_style, $font_name)
2006-03-16 20h05:28 _GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
2006-03-16 20h05:28 GUICtrlRTFSet ($edit, $out, 1)
2006-03-16 20h05:29 User Pressed SEND
2006-03-16 20h05:29 Typed: #CHATSAY
2006-03-16 20h05:29 Received #CHATSAY
2006-03-16 20h05:29 writeToScreen()
2006-03-16 20h05:29 Local $out = _RTFCreateDocument($font_name)
2006-03-16 20h05:29 $out = _RTFAppendString($out, $text & @CRLF, $hex_color, $font_size, $font_style, $font_name)
2006-03-16 20h05:29 _GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
2006-03-16 20h05:29 GUICtrlRTFSet ($edit, $out, 1)
2006-03-16 20h05:29 PlayWarning()
2006-03-16 20h05:30 User Pressed SEND
2006-03-16 20h05:30 Typed: #CHATSAY
2006-03-16 20h05:30 Received #CHATSAY
2006-03-16 20h05:30 writeToScreen()
2006-03-16 20h05:30 Local $out = _RTFCreateDocument($font_name)
2006-03-16 20h05:30 $out = _RTFAppendString($out, $text & @CRLF, $hex_color, $font_size, $font_style, $font_name)
2006-03-16 20h05:30 _GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
2006-03-16 20h05:30 GUICtrlRTFSet ($edit, $out, 1)

My specs, WinXP Pro, P4 2.7Ghz, 508Mb Ram...

BTW... I'm using the DLL that was provided >> here <<

Edited by Altalus

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I just tested on my home PC and it seem to work flawlessly... The box does'nt scroll down but I'll get that part eventually.

Weird... my work PC would be the proble then... really weird :)

Edited by Altalus

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

try

_GUICtrlEditLineScroll ($edit, 0, _GUICtrlEditGetLineCount($edit))
Holy~ You are the living bible of AutoIt code ! :o

Actually I used this instead:

_GUICtrlEditLineScroll ($edit, 0, 1)

That way it scrolls 1 line after the last one :mellow:

Now... this is all very fun but since it seem that ALL the frikking PC at work doens't like the DLL... sigh, gonna have to look why... and it is really the DLL calls that freeze or kill the app. I reverted back to the normal gray editbox (gray because it's read only) and it doesn't hang at all. I guess it's Sherlock Holmes time.

I'll let you know how it turns out... and Thank you very much for all the supprot. It's appreciated since you don't really have to :)

Thank you :)

Edited by Altalus

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

HAHA !

This line is the one creating all the problems :mellow: Now if I use this line :

_GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))

Or this one:

GUICtrlSendMsg($edit, $EM_SETSEL, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))

I'll get random freeze... If I don't, everything's ok !... weird... So the code that allow me to add the text at the end of the old text is making the hole thing freeze...

I tried to add a sleep(100) after the code, no effect... added WinWaitActive("vPop"), same problem... starting to be out of options :) lol

You think there's a way to add the test in the coding instead ?

I did tried to use this before without success:

Func writeToScreen($text, $hex_color, $font_size, $font_style, $font_name)
    Local $oldText = GUICtrlRTFGet($edit)
    Local $out = _RTFCreateDocument($font_name)
    $out = _RTFAppendString($out, $oldText & @CRLF, $hex_color, $font_size, $font_style, $font_name)
    $out = _RTFAppendString($out, $text & @CRLF, $hex_color, $font_size, $font_style, $font_name)
    GUICtrlRTFSet ($edit, $out, 0)
    _GUICtrlEditLineScroll ($edit, 0, 1)
    Sleep(200)
EndFunc

But sigh, that makes it freeze to... totally out of options here.

Edit #12214

It seem that it still freeze, just takes waaay more time... need to do more test...

Edited by Altalus

Share this post


Link to post
Share on other sites

I wrote a little online chat with lazycats rtfedit and used that solution

_GUICtrlEditSetSel ($edit, StringLen(GUICtrlRTFGet($edit)), StringLen(GUICtrlRTFGet($edit)))
First i thought that everything would be nice with that, but if the edit has about 200 lines that solution causes hard bugs, because the string is added at every position but not the end.

I think the problem is

StringLen(GUICtrlRTFGet($edit))
If u make
MsgBox(0,"",GUICtrlRTFGet($edit))
u'll see that rtfget makes a string with many brackets with the rtf information, so i think stringlen of rtfget doesnt give you the end position of the edit. As long as the edit is nearly empty it works rly fine because the string len is far longer (about 400(not sure)) then the real string in the edit. With a nonrtf edit, stringlen(GUIctrlread....)would give u the end, but not in a rtf edit. So i prefer that solution:

GUICtrlEditSetSel ($edit, 10000000, 10000000
I tried that and it works over ca.200 lines

"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

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