PDA

Click to See Complete Forum and Search --> : Extremely hard, newbies not apply...


Lord Orwell
Mar 2nd, 2001, 01:25 AM
Ok say i have a window open. On that window is a control based on the richedit control-i.e., it supports multiple fonts, colors, etc. for the text on it at the same time. How could i retrieve the information of the text formatting? Being able to retrieve it for one character or the entire document at once are both techniques i am willing to investigate.

And now that we have retrieved the information, could we find a specific character in that open window and change its formatting? One practical use of this would be to parse an aol chatroom for the wingdings font and convert them to arial in the chat window. I could come up with others. (note: i already have a method of removing ALL formatting in the chat room, but i have other reasons for wanting to read document formatting data. Perhaps access to the richtext information?

Mar 2nd, 2001, 03:01 PM
Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETFONT = &H30

Private Sub Command1_Click()
Dim HFONT As Long
Dim HDC_RTF As Long

HDC_RTF = GetDC(HWND_OF_RTB)
HFONT = CreateFont(14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Times New Roman")
SendMessage HWND_OF_RTB, WM_SETFONT, HFONT, True
End Sub

Lord Orwell
Mar 3rd, 2001, 01:42 AM
Megatron, thanks for the code. It looks like it will set the entire window to a certain font. Is this correct?

Mar 3rd, 2001, 10:33 AM
Yes.

Lord Orwell
Mar 3rd, 2001, 11:49 AM
I can't seem to get it to work.
I placed it in a command button on a form and had a richtextbox on the form (i tried a textbox also).
I set the richtext box font to wingdings, and typed something. I even made sure it was highlighted. Then i ran your code you posted. No effect. I even did a richtextbox.refresh. Am i using it wrong? Note: Maybe a line is missing. It is getting the device context but never using it. ANY help would be appreciated.

Mar 3rd, 2001, 03:56 PM
Hmmm...I tried it and it works fine in a TextBox, but you have re-type into a RTF box in order for it to work there.