Archived

This topic is now archived and is closed to further replies.

To rich edit or not

This topic is 5701 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, I''ve played with edit controls, but never with rich edit controls. I''m not sure if they are what I want. Here''s what I want. I want a scrollable text field where I can control the colors and fonts for particular (but not all) pieces of text. I don''t need or want the user to be able to change or edit the text, but I do need the user to be able to highlight and copy the text. I need to be able to dynamically update the text in the window. I am strictly using the Win32 API from C. Are rich edit controls what I am looking for? Or something else?

Share this post


Link to post
Share on other sites
Yeah, that''ll do it. Takes a little getting used to, but it''ll work. I wrote a control that displays output from a device connected to the serial port, and we need to display each line in different colors depending on the type of message. I don''t dynamically change the text (I set fixed-width or not on creation), but I know it can be done.

Your only option besides this (that I know of--speak up if anyone knows different) is to just write your own control, but that means handling _everything_ yourself. We were doing this before, but when I changed the control over to a Rich Edit control (rather than our own stuff), we instantly got copy/paste and mousewheel controls, which we would have needed to add ourselves.

The only pain with the control was that I didn''t like how horizontal scroll worked--as I would add lines to the end of the control it would jump around. I disabled horizontal scrolling and just have it wrapping now, but I''d really like that resolved some day.

Share this post


Link to post
Share on other sites
One benefit of a rich edit control versus a regular edit control is the amount of text that can be held by the control. A regular edit control is ''supposedly'' limited to 64 Kb. I say supposedly because I''ve gotten more to fit in them on NT - but I''ve been told that 9x does limit them to that amount of text.

From what you''ve described - I list box or list view might also work for you. But if you want to try your hand at the Rich Edit in C, I can send you some basic starter code if you want.

Share this post


Link to post
Share on other sites
quote:
Original post by LessBread
But if you want to try your hand at the Rich Edit in C, I can send you some basic starter code if you want.

That would be great. Send it over!

Thanks to both of you for your replies.

Share this post


Link to post
Share on other sites
I tried such thing myself once. But the only way I found to dynamically change properties was to get the text selected, add the properties you want and change the selection back (the user could type in my edit box). That made the text jump around in the box so I ended up writing my own edit control.

Share this post


Link to post
Share on other sites
I''m not entirely certain that I need to change the existing text dynamically, but I will need to append to the end of the existing text with new text. I would like to be able to do that without any unpleasant flickering.

Share this post


Link to post
Share on other sites
quote:
Original post by bishop_pass
Thanks for the email, LessBread. I haven''t looked at it yet, but when I come around to that part of my code, I will. Thanks again.


Sure thing. Let me know how it works out for you.

Btw - the cops found my car after two weeks. The theives removed the front end body parts, the radiator,alternator,battery and then stuck the front end of a Caprice on to it. Bastards totally ruined it. I ended up signing it over to the towing company so as to not have to pay them. I managed to hold on to the front license plate (an old black and gold plate) otherwise - $3000 gone - poof - just like that.

Share this post


Link to post
Share on other sites
If I recall, you said you had no comprehensive coverage on it. Geez, what a bummer.

I had a brand new ''95 Astro Van (I had a it for about 6 months) when the police called me one evening and said: "Would you mind going outside and telling us if your car is missing?".

I''m like "Huh?" I walk outside and there''s nothing but broken glass where I park my van. I go back inside and the police tell me over the phone that my van has been recovered (I just learned it had been stolen one minute ago) and they tell me it has been used in a crime. And they tell me that I can come recover it right now where they found it.

I go and get it. The ignition and steering column is jacked. The driver side window is busted out. There is blood behind the front seats. Apparently the crime it was used in was a shooting. Whether it was a gang hit, or a driveby, I don''t know, but apparently one of the passengers in my van took a hit as well. For the next day or two, I found a few stray bullets in my car. But anyway, when I recovered my van, I also noticed that the whole right side had been seriously swiped (dented and about a 6 foot long swipe).

I swear, if I ever catch some punk kid gang member in the act of stealing another car of mine, I will go into a rage and attempt to cause serious damage to said individual.

Share this post


Link to post
Share on other sites
What type of punks use a mini van for a drive by? Kids these days *tsk tsk*.

I''d just like to point out that there are a few different versions of rich edit controls for the different windows operating systems. You didn''t mention compadibility but it''s something to look out for =)

If all that matters is what you get in the end, why go through life?
~Michael Sikora

Share this post


Link to post
Share on other sites
Hey I''m in the exact situation as bishop_pass: I want differnt pieces of text, appended, with scrolling, and dont know much about rich edit... could you send that example code to me too LessBread?
wing_majin@hotmail.com

Share this post


Link to post
Share on other sites
quote:
Original post by bishop_pass
If I recall, you said you had no comprehensive coverage on it. Geez, what a bummer.


Yep - I only had liability insurance. Now I don''t have any car at all - which sucks - But since I''m not working at the moment that really only means I have to take the train to visit my Dad in Fresno. And - I live downtown so hopefully I''ll be able to find something within walking distance.

quote:
Original post by bishop_pass
I go and get it. The ignition and steering column is jacked. The driver side window is busted out. There is blood behind the front seats. Apparently the crime it was used in was a shooting. Whether it was a gang hit, or a driveby, I don''t know, but apparently one of the passengers in my van took a hit as well. For the next day or two, I found a few stray bullets in my car. But anyway, when I recovered my van, I also noticed that the whole right side had been seriously swiped (dented and about a 6 foot long swipe).


That''s an interesting story. A friend of mine in college had his van stolen too - it was used by some coyotes to smuggle in workers from Mexico. He got it back with out bullet holes. Another friend in college had his car stolen. The thief ended up wrecking it on the 805. When my buddy went to check out his smashed up car he found a cassette tape that belonged to the theif in the deck - he kept it - labled it ''the crash tape'' anyway.

wing_majin: I forwarded you the email I sent to bishop_pass. The code isn''t pretty, or complete. You''ll have to add to it to round it out. I did include a url to a richedit using app that was recommended to me by a friend - so that might help too. Non-MFC examples of using RichEdit controls aren''t the easiest to come by. What Guardian_Light said also holds as well - watch out for the 2 different dlls and the 3 different versions - MSDN does provide some clarification - but I don''t have a url handy.

Share this post


Link to post
Share on other sites
Thanks a lot. As for the scarceness of good rich edit reference material etc in non-MFC API.. I know all too well after having searched around and finding only holes. I haven''t looked at your stuff yet but ANYTHING is good.

Share this post


Link to post
Share on other sites
quote:
Original post by wing_majin
Thanks a lot. As for the scarceness of good rich edit reference material etc in non-MFC API.. I know all too well after having searched around and finding only holes. I haven''t looked at your stuff yet but ANYTHING is good.


Sure thing. Did you figure out how to color the background of your edit box? Here''s how you would do it for a listbox child of a dialog. Use this code (or similar) to handle WM_CTLCOLOREDIT and you should be good to go

  
// ---------------------------------------------------------------------------

// set foreground and background colors return the handle of a brush

HBRUSH Dlg_OnCtlColorListBox(HWND hwnd, HDC hdc, HWND listbox, UINT msg)
{
SetBkMode(hdc,TRANSPARENT); // leave background as is

SetBkColor(hdc,RGB(0,0,0)); // BLACK

SetTextColor(hdc,RGB(204,204,204)); // LIGHTGRAY

// return stock object to let the system deal with clean up

return (HBRUSH)GetStockObject(BLACK_BRUSH);
}

Share this post


Link to post
Share on other sites
I attempted creating a richedit control within my dialog like this:

//globally
HINSTANCE currInst;
HINSTANCE g_hInstRichEditDll;
HWND hRichEdit = NULL;

//in dialog messageProc

case WM_INITDIALOG:
{

g_hInstRichEditDll = LoadLibrary(TEXT ("Riched20.dll"));
if ( g_hInstRichEditDll == NULL )
{
return ( FALSE );
}


hRichEdit =
CreateWindowEx(WS_EX_STATICEDGE
, RICHEDIT_CLASSA
, TEXT("")
, WS_CHILD | WS_VISIBLE |
WS_HSCROLL | WS_VSCROLL |
ES_LEFT | ES_MULTILINE | ES_WANTRETURN |
ES_AUTOVSCROLL | ES_AUTOHSCROLL
, CW_USEDEFAULT, CW_USEDEFAULT
, CW_USEDEFAULT, CW_USEDEFAULT
, hwnd
, 0
, currInst
, NULL);

}

When I include the WS_CHILD style it doesn''t appear and then crashes when I exit the program. If I leave it out, it appears as a separate window overlapping the main dialog where I want it to be imbedded in. If it won''t act as a chil then how do I get it embedded in like a normal edit control? Since you can''t apparently do it the easy way in as a resource and set its properties there, how can I set that handle to it to a control ID so that it can be passed in the WM_COMMAND like normal controls.

Share this post


Link to post
Share on other sites
The extended style might be interfering - try using 0x0 and see if that makes a difference. With child controls created this way you can pass the ID as the HMENU parameter. And here''s another trick for getting the HINSTANCE from the parent window - one less global var to deal with.


  
hRichEdit = CreateWindowEx(0x0L // was WS_EX_STATICEDGE

, RICHEDIT_CLASSA
, TEXT("")
, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_LEFT|ES_MULTILINE|ES_WANTRETURN|ES_AUTOVSCROLL|ES_AUTOHSCROLL
, CW_USEDEFAULT, CW_USEDEFAULT
, CW_USEDEFAULT, CW_USEDEFAULT
, hwnd
, (HMENU) control_ID // control id

, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE)
, NULL);



Share this post


Link to post
Share on other sites