VB doesn't open correct page on local MSDN if you press F1 from code window. Open MSDN separately and in the "Index" tab type "StdPicture" to get the offline reference.
As the Wordpad of XP (SP2) can display hyperlinks the way you want, I thought may be we should try using XP's rtf dll.
In XP SP1 or later the dll is msftedit.dll and the class name is RICHEDIT50W. RichEdit version 4.0 (5.0 in XP2 ?).
So, I've created a window of that class and IT WORKED !
But creating a RTB from scratch is a very big task. vbAccelerator RichEdit Control uses similar method to load Riched20.dll (version 2.0 and version 3.0) library using the LoadLibrary function and create a RichEdit window of that version. So, if we load msftedit.dll library, then may be it can create a v4.0 window ?
Unfortunetly, that ocx is not running in my system. Some registry problem. (this XP installation is damaged). I've worked with this control before. It used to work smoothly.
So, if you try my idea and modify that control's code, I hope it will work.
BTW, I'm using XP SP2. If the attatched code can't create the window, open Wordpad and get it's classname and try with that class name.
Moeur, I'm using code that I believe I got from your GIFAnimatorV3 project to put smilies in a RichTextbox. I'm using the following code (in part) but when I do the background of the picturebox is not transparent.
Bill, I've found a serious problem. If you put just the following in a timer (where GIF is member of clsGIF) the app runs out of memory in a minute or so.
I don't know why the problem occurs, but if LoadGIF is in a timer then memory(?) gets used up and the program crashes. LoadGIF can be removed from the timer and still allow for animation of a smilie, but only one smilie.
I was able to resolve the problem by doing this
VB Code:
Private GIF() As clsGIF
'instead of
Private WithEvents GIF As clsGIF
You can't do WithEvents with an array but apparently it isn't needed (at least in my code). After that do the following outside of the timer
VB Code:
If UBound(GIF) < the_nbr_of_gifs_to_animate - 1 Then
I couldn't reproduce the out of memory error you get, however the solution you came up with is definitely the way to go. You don't want to have to keep reloading the gif.
I couldn't reproduce the out of memory error you get, however the solution you came up with is definitely the way to go. You don't want to have to keep reloading the gif.
In the version of my program that I sent you I don't believe that the LoadGIF code at that time was in the Timer.
Have you been able to figure out the non-transparent background problem?
OK, try this. It copies the frame to a picturebox first. The picturebox background color has been set to the same color as the RTB.
Each time you press the button it loads the next smilie from the resource file.
VB Code:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreateSolidBrush Lib "gdi32" ( _
ByVal crColor As Long _
) As Long
Private Declare Function FillRect Lib "user32" ( _
ByVal hdc As Long, _
lpRect As RECT, _
ByVal hBrush As Long _
) As Long
Private Declare Function SetRect Lib "user32" ( _
lpRect As RECT, _
ByVal X1 As Long, _
ByVal Y1 As Long, _
ByVal X2 As Long, _
ByVal Y2 As Long _
) As Long
Private Declare Function GetSysColor Lib "user32" ( _
OK, here you go.
Here is a sample project that replaces the tags with the proper animated smilie. The smilies are in gif files so you don't have to mess with resource files.
The project also demonstrates the hyperlink functionality we discussed earlier. this is because everytime you change TextRTF you have to reenable the EN_LINK effect for the hyperlinks. Since the animator messes with TextRTF, hyperlinks have to be updated too.
I'm sure there are some bugs and it can be cleaned up a bit but here it is.
Let me know how it works.
I'll also check this out but I don't find any problem in my code with animation vs. the EN_LINK effect.
Hmm...
I noticed in your code that you do the hyperlinks last. I assumed this was because if you set them first then changed RTB.TextRTF the blue links would go away. This is what happens on my system, so each time the animation timer fires and RTB.TextRTF is updated the links need to be reestablished.
OK, here you go.
Here is a sample project that replaces the tags with the proper animated smilie. The smilies are in gif files so you don't have to mess with resource files.
The project also demonstrates the hyperlink functionality we discussed earlier. this is because everytime you change TextRTF you have to reenable the EN_LINK effect for the hyperlinks. Since the animator messes with TextRTF, hyperlinks have to be updated too.
I'm sure there are some bugs and it can be cleaned up a bit but here it is.
Let me know how it works.
Bill (or anyone). I sometimes store my TextRTF in a string variable, manipulate the string and then replace the TextRTF with the string. Would you have any idea why when the string contains this
This is truly a great thread with loads of useful information. I stumbled upon it when I wanted to see what was involved in setting up a RTB to allow hyperlinks. Great stuff, Bill!
In addition to turning a URL you enter into a hyperlink (as in "Auto Detect and respond to URLs" above) you can turn ordinary text into hyperlinked text that points to a URL of your choice.
To do this the text in the Richtextbox has to have its link notification turned on. Then, as before, the form containing the Richtextbox has to be subclassed so that you can respond to user actions. I've created a class that simplifies these tasks.
This class has two events:
Clicked - raised when user clicks a hyperlink. MouseMove - raised when the user moves the mouse over a hyperlink
And three methods
Initialize - called once to attach the RTB to the hyperlink class InsertHyperlink - can hyperlink selected text or insert new text and hyperlink it. RefreshHyperlinks - Unfortunately, whenever the richtextbox's TextRTF property is changed, the RTB will lose all link notification information. To remind the RTB of previously hyperlinked text you must call this method each time the textRTF property is changed.
Here is an example of how to use the class
Code:
'instantiate and initialize the class
Dim Hypertext As clsHyperText
Set Hypertext = New clsHyperText
Hypertext.Initialize RTB
'hyperlink the word "this" in the Richtextbox
RTB.Find ("this")
Hypertext.InsertHyperlink ("http://www.vbforums.com")
To respond to user action on the hyperlinks, simply place code in the events.
Code:
Private Sub Hypertext_Clicked(Button As Integer, URL As String, UnderlyingText As String)
'launch the browser here
If Button = vbLeftButton Then
ShellExecute 0&, "OPEN", URL, vbNullString, "C:\", SW_SHOWNORMAL
Else
'popup menu?
Debug.Print URL, UnderlyingText
End If
End Sub
Attached is a demo project which contains the class.
Here is a control that shows you how to add animated GIF images to a Richtextbox. This control was built to replace VBCode smilie tags with their corresponding animated images. It takes advantage of my VB GIF Animator Control and the PictureToRTF function in my above post Insert Pictures.
I placed this functionality on a usercontrol because it uses a timer and an array of picture boxes. The GIFs cannot by placed into the richtextbox transparently, so I change the background of each image to match the background color of the RTB.
The control has two properties
BackColor - set this property to the backcolor of your Richtextbox to simulate transparency. This property can only be set from code and cannot be changed once pictures have been inserted into the RTB.
FrameInterval - This interval in ms, affects the speed of the animation.
two methods
LoadIcon - load a GIF file and its corresponding tag into the control ReplaceTags - Replaces each tag in the Richtextbox text with its corresponding animated image.
and one event
NextFrame - Raised at each frame advance interval.
The following is an example of how you might initialize the control
Code:
'set the picture backgrounds to match the RTB background
GIF.BackColor = RTB.BackColor
'load some icon files along with the corresponding tags
Path = App.Path & "\icons\"
With GIF
.loadIcon ":)", Path & "smile.gif"
.loadIcon ":(", Path & "Frown.gif"
.loadIcon ":o", Path & "redface.gif"
.loadIcon ":D", Path & "BigGrin.gif"
End With
Now to replace all the tags in the RTB text with the proper smilie
Code:
GIF.replaceTags RTB
Attached is a demo project which illustrates the proper use of this control.
I've got a problem with insertion of rtf, when the text in the target rtb control is colored and the text/rtf being inserted has some colors also, when inserted the color of the inserted rtf is lost... :-( Any workarounds there? :-)
Regards,
™
As a gesture of gratitude please consider rating helpful posts. c",)
Using your function to insert. :-) For instance, if the target rtb control got some colored text then the rtf being inserted got some colored text also, the color of the rtf being inserted is overridden, the color table is not updated... :-(
Regards,
™
As a gesture of gratitude please consider rating helpful posts. c",)
what you're saying still does not make sense to me.
what do you mean by my function to insert :-) ?
Do you mean inserting an animated GIF? If so then how can that have colored text?
what you're saying still does not make sense to me.
what do you mean by my function to insert :-) ?
Do you mean inserting an animated GIF? If so then how can that have colored text?
Please explain in detail or supply example code.
For example, the ff. is the tex of the target rtb: dee-u
And the text being inserted is: moeur
If you will try to insert the rtf of moeur to the rtf of dee-u then the colors of meour is not preserved, it is being overridden. Clear now? :-)
Regards,
™
As a gesture of gratitude please consider rating helpful posts. c",)
Ok, here is further explanation since I don't have VB6.0 here.
RichTextbox1 control has the 'dee-u' text (with the colors as in my previous post), RichTextbox2 control has the 'moeur' text (with the colors as in my previous post), get the TextRTF of Richtexbox1 then insert it, using your function to insert rtf, in the RichTextbox2, perhaps in the middle of 'm' and 'o'.... The color of 'dee-u' will be overriden... :-(
I hope I made myself clear already.... :-)
Regards,
™
As a gesture of gratitude please consider rating helpful posts. c",)
Moeur, thanks for all of this, it's great and alot of it is what I have been looking for, although I don't confess to totally understand all of the code.
I am working through it slowly.
I have used the hyperlink code and there are a couple of question I have:
Firstly, I would only like to enable the autourldetect under certain circumtances. How can I turn it off?
Secondly, if there is a link in the RTB, if I click anywhere in the RTB it opens the link. Is this how you planned it?
I have other text in the RTB which I would be editing and when I click somewhere in the RTB, it opens the link.
If the non-link text is first in the RTB it's ok, but if I click anywhere after the link, where there is no text, just space, it still selects the link and opens the link.
I hope you can follow what I am trying to explain.
I have just done a straight copy of your code in the example project, with the exception of this line which is not in the Form_Load, but in a treeview node_click.
vb Code:
EnableAutoURLDetection RTB
If somebody helps you, take time to RATE the post. I do.
"FAILURE IS NOT AN OPTION. It comes bundled with the software."
Below are some of the threads that have helped me along the way:
I have now used the following to turn off the detection.
I just wondered, being new to subclassing, is this ok, or do I need anything else.
It seems to work ok.
vb Code:
Public Sub DisableAutoURLDetection(rtb As RichTextBox)
Set FormSubClass = Nothing
End Sub
If somebody helps you, take time to RATE the post. I do.
"FAILURE IS NOT AN OPTION. It comes bundled with the software."
Below are some of the threads that have helped me along the way:
Public Sub DisableAutoURLDetection(RTB As RichTextBox)
'disable auto URL detection
SendMessage RTB.hwnd, EM_AUTOURLDETECT, 0&, ByVal 0&
'turn off subclassing
FormSubClass.Unsubclass
End Sub
As to your other problem:
I only see this when the hyperlink is the very last text in the richTextBox. This is a bug in the richtextbox itself. To eliminate this problem, put something after the hyperlink even just a new line.
Public Sub DisableAutoURLDetection(RTB As RichTextBox)
'disable auto URL detection
SendMessage RTB.hwnd, EM_AUTOURLDETECT, 0&, ByVal 0&
'turn off subclassing
FormSubClass.Unsubclass
End Sub
As to your other problem:
I only see this when the hyperlink is the very last text in the richTextBox. This is a bug in the richtextbox itself. To eliminate this problem, put something after the hyperlink even just a new line.
Thanks moeur.
I will change the Disable code.
Is this to change the message from the RTB back to, I guess the form?
I eventually realised that the way to do this was to put the link first, then the text afterwards.
Thanks for all your hard work.
If somebody helps you, take time to RATE the post. I do.
"FAILURE IS NOT AN OPTION. It comes bundled with the software."
Below are some of the threads that have helped me along the way: