• Welcome to Valhalla Legends Archive.
 

Make the scrolling stop ...

Started by Eli_1, June 01, 2004, 06:21 PM

Previous topic - Next topic

Eli_1

How can I add colored text to a RichTextBox control, while stopping it from scrolling?

I've done it using SendMessage and .Text, but that was ghetto and had a few problems:
1) I couldn't add colored text.
2) 8:10 users of the program would have seizures due to the horrible flickering.

Thanks in advance...

MyndFyre

Quote from: Eli_1 on June 01, 2004, 06:21 PM
How can I add colored text to a RichTextBox control, while stopping it from scrolling?

I've done it using SendMessage and .Text, but that was ghetto and had a few problems:
1) I couldn't add colored text.
2) 8:10 users of the program would have seizures due to the horrible flickering.

Thanks in advance...

What are you trying to do, exactly?  How is your Add-Text function set up?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Eli_1

There is no addtext function set up currently.

Here's a simple one I use sometimes:

Public sub AddText(atoutput as richtextbox, byval data as string, color as colorconstants)
   with atoutput
       .selstart = len(.text)
       .selcolor = color
       .seltext = data
       .selstart = len(.text)
   end with
end sub


My question wasn't very clear, I'm realizing. It's for a simple chat bot, where text is constantly being added to the textbox.

But say someone says something funny like, "I like poopie", and I want to quote it. I have to scroll up and copy and paste it. But say he says something else while I'm trying to copy it, I'll be scrolled to the bottom again, because of .SelStart.

This is what I'm trying to get around...

hismajesty

Quote from: Eli_1 on June 01, 2004, 06:21 PM2) 8:10 users of the program would have seizures due to the horrible flickering.

Use LockWindowUpdate to stop the flickering.

Public Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) As Long

Eli_1

While that would work, the way I made it work would mean no colors -- a very boring chat bot.

Stwong

Write the entire textbox yourself using the windows gdi and backbuffers so it wont flicker? :D

This advice is probably thoroughly unhelpful, but there are gdi tutorials on google ;)

Grok

Quote from: Stwong on June 01, 2004, 11:02 PM
Write the entire textbox yourself using the windows gdi and backbuffers so it wont flicker? :D

This advice is probably thoroughly unhelpful, but there are gdi tutorials on google ;)

A good idea several of us have considered for years, but nobody has even started.  We wanted to write a Starcraft-styled ListBox as a COM control in an ActiveX DLL, then distribute so VB programmers would have a better choice than a RichEdit control (RichTextBox) from which to start their bots.

CrAz3D

Quote from: Grok on June 01, 2004, 11:11 PM
Quote from: Stwong on June 01, 2004, 11:02 PM
Write the entire textbox yourself using the windows gdi and backbuffers so it wont flicker? :D

This advice is probably thoroughly unhelpful, but there are gdi tutorials on google ;)

A good idea several of us have considered for years, but nobody has even started.  We wanted to write a Starcraft-styled ListBox as a COM control in an ActiveX DLL, then distribute so VB programmers would have a better choice than a RichEdit control (RichTextBox) from which to start their bots.
What would a StarCraft styled listbox be?
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Adron

Quote from: Grok on June 01, 2004, 11:11 PM
A good idea several of us have considered for years, but nobody has even started.  We wanted to write a Starcraft-styled ListBox as a COM control in an ActiveX DLL, then distribute so VB programmers would have a better choice than a RichEdit control (RichTextBox) from which to start their bots.

A Starcraft-styled ListBox is suboptimal because that ListBox doesn't support selecting and copying text. It might be better to just write the whole thing from scratch.

iago

* iago points to javax.swing.JTextPane

oops! :-)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


MyndFyre

Quote from: Adron on June 02, 2004, 04:31 AM
Quote from: Grok on June 01, 2004, 11:11 PM
A good idea several of us have considered for years, but nobody has even started.  We wanted to write a Starcraft-styled ListBox as a COM control in an ActiveX DLL, then distribute so VB programmers would have a better choice than a RichEdit control (RichTextBox) from which to start their bots.

A Starcraft-styled ListBox is suboptimal because that ListBox doesn't support selecting and copying text. It might be better to just write the whole thing from scratch.

I'm using a managed wrapper of the MSHTML DHTML editor control.  I haven't built in the logic for it to not scroll, and honestly, I've only thought about it a little.  But look how easy it is:


void AddChatEvent(ChatEvent ce) {
 // this loop ensures that only 100 events are displayed at a time.
 // eventQueue is a Queue object (wow!) that stores the last 100 chat events (wow!)
 while (eventQueue.Count >= 100) {
   ChatEvent removing = eventQueue.Pop() as ChatEvent;
   // sbText is a StringBuilder object, for mutable, buffered strings
   // it holds the entire HTML that should be displayed
   // Instance method ChatEvent.ToString() converts the chat event into HTML text based on the event type
   // and data.
   sbText.Remove(removing.ToString()); // that takes the oldest chat event out.
 }

 // now we append the new event.
 sbText.Append(ce.ToString());

 // find the element
 // he is the wrapped control, for HtmlEditor.  HtmlEditor.Document is a wrapper for the IHTMLDocument,
 // IHTMLDocument2, IHTMLDocument3, IHTMLDocument4, IHTMLDocument5, and IHTMLDocument6 COM
 // interfaces.
 // To use these, you have to reference the interop assembly Microsoft.mshtml.dll
 IHTMLElement element = he.Document.getElementById("armabot_textinsert");
 element.innerHTML = sbText.ToString();

 // now if I want to scroll it, I find the element that I just inserted by its ID which is uniquely generated by the
 // ChatEvent class.
 IHTMLElement newElement = he.Document.getElementById(ce.Identifier);
 newElement.scrollIntoView(1 as object);
}


The HTML code that ChatEvent.ToString() emits is something like the following:


<span id="CE10352"><div class="time">[1.32.55 pm]</div> <div class="username">MyndFyre:</div> <div class="ChatText">Blah blah blah</div></span>


The nice thing is that the HTML box also allows me to copy as plaintext or HTML:

Quote
[1.25.23 pm] MyndFyre whispers: Instance ban is currently disabled.
[1.29.47 pm] Slackware joined the channel with Warcraft II: Battle.net Edition.
[1.29.49 pm] e1-: I have designated Slackware
[1.38.49 pm] R.a.B.B.i.T[e1] has left the channel.


<SPAN id=eid48><SPAN class=time>[1.25.23 pm]</SPAN> <SPAN
class=whispername>MyndFyre whispers:</SPAN> <SPAN class=whisper>Instance ban is
currently disabled.</SPAN></SPAN><BR><SPAN id=eid49><SPAN class=time>[1.29.47
pm]</SPAN> <SPAN class=userjoin>Slackware joined the channel with Warcraft II:
Battle.net Edition.</SPAN></SPAN><BR><SPAN id=eid50><SPAN class=time>[1.29.49
pm]</SPAN> <SPAN class=moderatorname>e1-:</SPAN> <SPAN class=ChatText>I have
designated Slackware</SPAN></SPAN><BR><SPAN id=eid51><SPAN class=time>[1.38.49
pm]</SPAN> <SPAN class=userleft>R.a.B.B.i.T[e1] has left the
channel.</SPAN></SPAN>


MSHTML HTML isn't exactly pretty, but it gets the job done :)

Anyway, that's what I use.  If you're up for a little bit of a learning curve, MSHTML IMHO is worth it.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Adron

That looks nice. Adding text doesn't affect current cursor location, scroll position or similar? Can you type into it too, if you don't make it read-only?

MyndFyre

Quote from: Adron on June 02, 2004, 03:43 PM
That looks nice. Adding text doesn't affect current cursor location, scroll position or similar? Can you type into it too, if you don't make it read-only?

If you don't use the scrollIntoView, then no, it won't affect scroll position.  There's a way to make it editable as well, although I'm not familiar with all of the mechanics behind it (I'd have to look at the source, which I have available, but am not familiar with).  Cursor location is probably the same way.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Dyndrilliac

#13
Eh, Why couldn't you just write a function that locks the chat temporarily, and during that time, filter all messages recieved into a queue type mechanism - then once chat is unlocked, have the queue attractively unload the messages it recieved onto the RTB and continue program flow normally?

Edit: Here's Something I wrote quickly.Public Type FQueue
   Username As String
   Flags As Long
   Message As String
   Ping As Long
End Type

Public MQueue() As FQueue
Public QMax As Integer

Public Sub InitializeFQueue()
   QMax = 100
   ReDim MQueue(QMax)
End Sub

Public Function AddMQ(Username As String, Flags As Long, Message As String, Ping As Long)
   On Error GoTo ErrHandle
   Dim i As Integer
Retry:
   i = 0
   Do Until MQueue(i).Message = vbNullString
       i = i + 1
   Loop
   MQueue(i).Username = Username
   MQueue(i).Flags = Flags
   MQueue(i).Message = Message
   MQueue(i).Ping = Ping
   Exit Function
ErrHandle:
   ReDim Preserve MQueue(QMax)
   GoTo Retry
End Function


Then, when you have the OnTalk event and the chat is locked, do something like...:Public Locked As Boolean
Public LockTimer As Timer

Public Sub LockTimer_Timer()

   Dim i As Integer
   For i = 0 To MQueue(QMax)
       If MQueue(i).Username = vbNullString Then
           Exit Sub
       End If
       AddC frmMain.Chat, vbGreen, "<" & Mqueue(i).Username &.......<you get the picture>...
   Next i
   
   InitializeFQueue

End Sub

Public Sub OnTalk(Username As String, Flags As Long, Message As String, Ping As Long)

Dim QInterval As Integer

If Locked = True Then
   AddMQ Username, Flags, Message, Ping
   LockTimer.Enabled = True
   LockTimer.Interval = QInterval
End If

End Sub


Note: The above is untested, but for the most part it looks right.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

UserLoser.

#14
Quote from: Grok on June 01, 2004, 11:11 PM
A good idea several of us have considered for years, but nobody has even started.  We wanted to write a Starcraft-styled ListBox as a COM control in an ActiveX DLL, then distribute so VB programmers would have a better choice than a RichEdit control (RichTextBox) from which to start their bots.


Sounds like a good idea, maybe I can take a shot at this..