Reputation: 36101
I'm writing a small app that needs to be small and run on old systems. That's why I can't use .NET.
How can I change the color of the Edit control?
Here's the .NET code:
textBoxLog.SelectionColor = color;
textBoxLog.AppendText(String.Format(s + "\n", parameters));
Update
Okay, so I managed to place the control on my form. How do I use the EM_SETCHARFORMAT message?
LoadLibrary(TEXT("Riched32.dll"));
CreateWindow("richedit", text, WS_VISIBLE | WS_CHILD | type, left, top, width, height, parent, NULL, NULL, NULL);
Update 2
I solved it. Turned out to be pretty easy:
SendMessage( textBoxLog , EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&RedFont);
Where RedFont is
CHARFORMAT cf;
memset( &cf, 0, sizeof cf );
cf.cbSize = sizeof cf;
cf.dwMask = CFM_COLOR;
cf.crTextColor = RGB(255,0,0);
CHARFORMAT RedFont = cf;
Don't forget to include "richedit.h"
Upvotes: 0
Views: 376
Reputation: 36026
In the beginning, there was only darkness and chaos. And lo the users cried out "These UIs are all different and what one learneth in one cannot be applied in another. They are a stench unto our nostrils and none can abide by them!"
And the Scientists at PARC heard the users cries, and invented the modern WYSIWYG GUI. And they looked and saw that the UI was consistent. And cut was in one application as it was in another, and so was paste and so on. All the commands, Quit and Help amongst them, where in their appointed place. and it was good.
Apple and Microsoft stole the work of PARC, but made it popular, which is a good thing, and the users were happy, and they could cut and paste, and click on any button or control, knowing it in one application as they knew it in others.
And, for many years, this state of affairs continued, and the users were satisfied.
But software designers and developers were aghast, and tore and rend their clothes, and covered themselves with ashes. For their software was easy to use, and users did know how to use it. And their was no differentiation amongst the buttons, and scrollbars, and menus, for they were standard, in look, and in feel. And a menu in one application did look like a menu in another application. And selected text in one application did look like selected text in another.
And the designers, and developers, and indeed the marketers, were successful. For lo did Adobe listen to them, and invent Flash. And Microsoft did listen to them, and invent Silverlight and WPF. And Apple said, none shall make Apps for OS X or the iPhone or indeed the iPad but through Cocoa, for it is as PARC said. But they were largely ignored.
And so, again, chaos did return to the world.
So no - you can't change the selection color of standard controls - including the native EDIT and RichText controls. They come from an earlier time where things like the font, and color's used by the GUI for standard purposes where there for the user to set as THEY saw fit.
You can change the color of the text in the richedit control, but the selection color is one of those user settings, and while it can be changed by subclassing, is a lot more work than a one line "SetTheSelectionColor" call.
Upvotes: 5
Reputation: 941407
The TextBox class doesn't have a SelectionColor property. You are using a RichTextBox.
Use a rich edit control in native code, EM_SETCHARFORMAT message.
Upvotes: 6