Skip to main content
gamedev.net
🔒 Locked

RichEdit HELL!

Started by Pse Dec 21, 2004 at 9:48 PM 7 replies 1.3k views
Original Post
Pse
Pse
Hi! I've been trying to get a RichEdit control to work properly during the past few days, but it seems that Bill's got some personal stuff against me, or something like that. The problem is as follows: I'm programming enterily based upon the Win32 API, avoiding anything MFC-related. I've been able to set up a RichEdit control in a dialog box and it's working perfectly, except for one little thing: text colouring! I am able to change fonts and set the character size, but I simply cannot get the control to change the selected text to other colours that are not black (which also seems to be the default AUTOCOLOR in my system, so I guess that's got something to do with this issue). The text is selected using the EM_SETSEL message and the CHARRANGE structure. I have obviously specified the corresponding dwMask (CFM_COLOR) of the CHARFORMAT structure (the former having a hex value of 0x40000000), and I'm using the EM_SETCHARFORMAT message. I have specified both SCF_ALL and SCF_SELECTION (not together, of course) parameters trying to get this thing to work, but that's not the problem, as I can already change other parameters such as the font and its size. I simply cannot change the color. I set the crTextColor member of the CHARFORMAT structure to a COLORREF value given by the RGB macro. Example: CHARFORMAT cr; cr.cbSize = sizeof(cr); cr.dwMask = CFM_COLOR; cr.crTextColor = RGB(127,127,127); SendDlgItemMessage(hWndMain2, IDC_BARCODE, EM_SETCHARFORMAT, SCF_ALL, (long)&cr); Being hWndMain2 the handle of the Dialog-window, IDC_BARCODE the int value of the RichEdit-control resource. Any help would be greatly appreciated. [EDIT]Adding new info: I have tried both RICHED32.DLL and RICHED20.DLL (with their respective classes, of course), the result being the same as before. I can copy-paste any text from other RichEdit editors in my RICHEDIT window and they show up correctly (coloured and everything)...:(
robinei
robinei
Are you going to use it for code editing? If so, just use Scintilla.
Pse
Pse
Thanks for your reply.
In fact, it's a kind of minimalistic application dealing with special font types (barcodes and stuff). I don't need any sort of sytax highlighting or anything like that, but I do need to set different colours for the special font types. I intend to avoid using powerful (I suppose Scintilla is so) classes or libs, as the only features I really need are:
- Selectable fonts. (Done)
- Different colours. (Can't make it work)
- Size setting. (Done)

The odd thing is that I pass all the parameters together in the CHARFORMAT structure, but only those regarding the font-name and the size are actually set. I DO put the correct flags in the dwMask setting...it just doesn't...well...obey me?
LessBread
LessBread
Here's some C code for a notepad clone that uses the RichEdit control: TinyPad.


"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Pse
Pse
Thank you, LessBread. I had already had a look at that little app, however, I haven't been able to find the Text Colouring procedure as of yet. I guess I'm kinda tired, I'll give it another look, as it seems the Win32API works great for that app. Just by chance, don't you remember in which file was that procedure? (don't bother to look for it if you don't remember, I'll eventually find it).
=)
Pse
Pse
Already found it, nevermind. I'll give you an update if I can make it work with this, thank you again!
Anon Mike
Anon Mike
The code you posted didn't initialize dwEffects. The symptoms sound like the CFE_AUTOCOLOR bit is set in which case it will ignore whatever color you give.

The general pattern to avoid stuff like this is to always initialize the structure to 0. Try using:

CHARFORMAT cr = {0};

This will zero-initialize all members of the structure.
-Mike
Pse
Pse
I can't believe it Anon Mike, I would have sworn I had correctly initialized the structure, but when you mentioned that I doubled checked just in case...surprise...I had forgotten to null the entire thing! I can't believe it, I've been working my ass off the last couple of days to figure this out, and it turns to be this silly thing. I apologize, guys, it was a complete waste of time!
Thank you all again!

BTW, LessBread, I haven't been able to get TinyPad to compile yet...I'll look at it later, it's nice to see that there are apps out there still using the ol' Win32 API instead of MFC.
LessBread
LessBread
Quote:
Original post by Pse
BTW, LessBread, I haven't been able to get TinyPad to compile yet...I'll look at it later, it's nice to see that there are apps out there still using the ol' Win32 API instead of MFC.


I can't vouch for TinyPad completely as I didn't write it. It likely hasn't been tested on other compilers. It's Win32 api though.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.