Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi All :)

I have a dialog based application that has a long single line edit control among other things. As the user types in, it should display numbers in one color (blue), some symbols should be in another color (lets say red), and also I have a set of keywords that have ot be in a different color (green). all the rest of the test should be in the default black color.

This task proved to be much more complex than I thought. I tried to write my own CEdit derived control but it didn't worck as I expected, then I tried CRichEditCtrl which had all the signs to work but it has that Win2000 style border which looks ugly, since I have other edit controls close to this one and it would look really inappropriate for this particular edit control to have a different border.

I can write a CWnd derived edit control from scratch and attach it to a static control resource without border and draw the border in my OnPaint, but that solution looks very inelegant and sloppy to me...

Please give me an advise what should I do? :)
Thanks a lot in advance!
Posted
Comments
Sergey Alexandrovich Kryukov 16-Oct-12 13:39pm    
What border? Rich edit is based just on raw Win32; it shows what your system does. Whatever you do with C++ and MFC, rich edit is the primary way to go.
--SA
Ivan Ivanov 83 16-Oct-12 14:03pm    
Well I did incorporate CRichEditCtrl in my app and when I started my app I saw that the control's border is not like according to WinXP theme which must be a simple brown-gray rectangle around the client area of the control, but has this 3D-like sunken border, that's Win2000 style. When I removed the Border property from the resource the border completely disappeared and the text was no longer verticaly centered, it appeared at the upper left corner of the control. Then I noticed that the rich edit resource look alittle different even in the resource editor, the border is alittle "deeper".. I use VS2003...

I tried all combinations of the Border property and the Client Edge property of the rich edit 2.0 resource without result. There is either sunken 3D border or none.
Sergey Alexandrovich Kryukov 16-Oct-12 14:40pm    
I don't want to look at it, but usually you can 1) remove border, 2) custom draw, 3) enable style use for all the application (did you?). As I can see, on Windows, for anything colored or formatted, Rich Text is mostly used... You can also use raw Win32 API.
--SA
Ivan Ivanov 83 17-Oct-12 6:55am    
If you asking did I include/enable the use of 'common control manifest' that allows the program to use the current windows theme for drawing the controls, the answer is Yes. This is why I'm puzzled onto why the rich edit control is the only one that's not affected by the manifest.

Unfortunately I can't agree with your solution to remove the border and custom draw it because (as I just tested it) when you add an OnPaint handler in your CRichEditCtrl derived class all the drawing is handed to it and nothing but the moving caret is shown as you type.

I'm starting to reconsider the ugliness of that border though... :D I'm going to use CRichEditCtrl for my purpose for now. And wrire my own CWnd based control in some other time.

The good news is that thanks to your help now I know that the rich edit 2.0 resource can show the caret on top of all things I draw in the client area of the control, which is not the case with the normal CEdit control which draws everything (text with the default black color) on top of my drawings (the coloredt text). Thah's why when I start writing my custom control I'll use rich edit 2.0 resource in the resource editor as a place holder and caret behaviour handler. ;)

So thanks a lot for your help!!! :)
Sergey Alexandrovich Kryukov 17-Oct-12 13:29pm    
You are welcome.
OK, think a little more and consider accepting my answer formally (green button) -- thanks.
--SA

1 solution

There a nice user control here with that requirements:

Colorizing edit control[^].
 
Share this answer
 
Comments
Ivan Ivanov 83 17-Oct-12 7:01am    
This is one way to do it. I'll accept this answer even though it's not exactly what I want. I would rather implement my own contol based on this one when I have more time. For now I would have to live with the ugly border of the rich edit control. But it is still a massive help! So thnaks a lot. :)
ErnestoNet 17-Oct-12 7:23am    
Writing your own CEdit derived control will be a lot of work (even with the help of the article). You're right to use the rich edit till you have time.
ErnestoNet 17-Oct-12 7:34am    
About the border of the rich edit, there's an article for that too!

http://www.codeguru.com/cpp/w-d/dislog/miscellaneous/article.php/c8729/XP-Theme-Support-for-Rich-Edit-and-Custom-Controls.htm

Some help by Microsoft here...
http://msdn.microsoft.com/en-us/library/dd373487(v=vs.85).aspx
Ivan Ivanov 83 23-Oct-12 10:34am    
Sorry for the late replay, I just wanted to thank you for those links. I haven't looked at them in detail but even after the quick look I can say they give exactly the info I needed!

so thanks again :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900