I want to be able to set the foreground and background colors of the RichEdit control to mimic the behavior of a step debugger. I can set the text color OK when it is on a white background (black on white), but does not work if I want to invert the color scheme (white on black). When I try to invert the colors the foreground color is set correctly, but the background is not. What am I doing wrong?
This is the code I'm using to set the foreground/background colors:
Sub ife_SetRichTextColor(ByVal nFGColor As Dword, _
ByVal nBGColor As Dword)
Local cf As CHARFORMAT2
'------------------------------------------------------------------------
cf.cbSize = LEN(cf) 'Length of structure
cf.dwMask = %CFM_COLOR 'Set mask to colors only
cf.crTextColor = nFGColor 'Set the new text color value
cf.crBackColor = nBGColor 'Set text background color, THIS DOES NOT
'SEEM TO WORK WITH ANY COLOR OTHER THAN
'WHITE.
Call SendMessage(HWND_DOC_TXT, %EM_SETCHARFORMAT, %SCF_SELECTION, VarPtr(cf))
End Sub
Any ideas?
Unfortunately, I don't have much experience in manipluating a RichEdit control in the fashion that you need. I will find time to do some research into it.
In the meantime, do you really need a RichEdit control. That is, do you need the line wrapping? If not, it may be easier to load your text, line by line, into an owner drawn listbox. Using an owner drawn listbox would allow you to have full control over every aspect of how each line is painted/displayed. Just a thought.
Paul,
Well, I need the text editing capabilities and syntax highlighting that the RichEdit control offers, so that is why I'm using the RichEdit control. I don't need line wrapping so I'm not using it. Still trying to get line numbering to work with RichEdit, but that is another chapter in this ongoing saga. To date I have created a ListView editor that has much of the basic functionality as the RichEdit control and planned on using that, but the project was growing way too big for the benefit gained, so again, I switched to RichEdit.
The basic idea for this app is an editor designed to create input files to be used in the design of highways. The input file holds commands to perform specific tasks, but sometimes I need the ability to input these commands line by line, to look for errors or command parameters that are out of range, that sort of thing. This is why I need the syntax highlighting and the ability to make the RichEdit control function like a source code step debugger. The input file commands are the easy part, RichEdit seems to be the stumbling block.
What I think is strange is the fact that there doesn't seem to be much useful information about the RichEdit control, yet it is used extensively in various apps. Seems RichEdit is just "out there" and you use it at your own risk.
Most frustrating.
JR
Found the answer to my question and posted the solution in the source code forum if anybody is interested.
JR
Great stuff! Thanks for sharing your solution. My apologies for not helping (I haven't been able to help many people lately due to my schedule and travelling). :(
In order to display line numbers in a gutter/margin in a rich edit control you will need to use OLE. The rich edit control uses what is known as the Text Object Model(TOM).
The code to implement this is not much longer than the standard Windows API one would use if the lines in the rich edit control where all the same height.
Since you have a registered copy of Phoenix, send me an email if you would like to try the sample project from the next version of Phoenix.
Go hunt down and buy on O'Reilly book called ---
"RTF Pocket Guide" by Sean M. Burke
It explains many "mysteries" about RTF code. When you read the book you will wonder how it got to be such a mess (oh yeah -- Microsoft) but it will help you sort out how to format just about anything.
QUICK TIP
Take WordPad and format what you want then look at the resulting RTF file with a text editor. Don't try it with Word because it addes TONS of overhead RTF junk in the file.