• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

visual studio .net (C++) rich edit control help

RancidWAnnaRIot

EspantaPajaros
Joined
Feb 19, 2004
Messages
11,033
Hello,

does anyone know where i ca nfind good help on how to use a rich edit control.. i'm using visual studeo .net.. and i don't even know where to start.. like i can just get a rich edit control to pop up.. and i can type.. but i do'nt know how to change colors and crap like that

gawd i'm so depressed... i hate school :( :( :(
 
My book has a great section on it. Are you using MFC?

What specific questions do you have? Just the colors and formatting?
 
Hi. I've actually did this early this year for work. It didn't work with a darn for what I wanted so I wrote my own (color-coded programming editor).

I agree with the prior post using MSDN, or whatever you might have for help. Also, if you throw it up on google you'll get the same info from Microsoft's website.

I haven't gone to .NET stuff yet, so this may or may not be relevant. But if you can, include MFC with your project (link it in) and use CRichEditCtrl. It'll help you with some of the function calls.

Do you have to allow font name and font size changes? Are you doing combo boxes for these? But look in help under common control, rich edit and you'll have the stuff you need there. If you have specific questions, ask away. Otherwise have fun with it.
 
yea i'm using MFC.. and the MSDN stuff doesn't help too much.. i ended up learning off stuff people posted in C++ forums.

I was just trying to change colors and different things.. i may need to do other more complicated stuff later.. so i might post on this same thread later.. but for now.. i'm okay..

as for MSDN.. like man.. i always have trouble finding info on that thing.. i couldn't find an example on how to do things like change colors.. etc. on MSDN..

thanks for th replies..
 
Okay, i got a question now..

so say i created another object of type Cricheditctlr

how do i display it? or create a new windoe for it??

does this even make sense?
 
RancidWAnnaRIot said:
Okay, i got a question now..

so say i created another object of type Cricheditctlr

how do i display it? or create a new windoe for it??

does this even make sense?
The answer depends on how you want to display the control. In the view? In another dialog? In the same dialog? It's own top-level window?

If it's in another dialog, then just create a new dialog resource and add the rich edit control to the template for that resource. Then, add a CDialog clas for that template with the ClassWizard. Create an instance of your new CDialog-derived class, call its DoModal() method, and there you are.

If it's in its own pop-up window, you'll want to create a CWnd-derived class and create your rich edit control in response to the WM_CREATE message in that CWnd-derived class. CWnd gives the frame and non-client area, while the rich edit gives the client area. You can measure the client rectangle with CWnd::GetClientRect() and use it to size the rich edit control child. Don't forget to give your rich edit control WS_CHILD.

If it's in a view, use the ClassWizard to create a CRichEditView and register it to your document type by creating a new document template with your existing frame and document classes. (There's already code in your app to do this.) You'll find a member of the newly registered document template will create the trio for you.

I think you can search MSDN for any of these keywords or member names, too. The MFC FAQ is pretty stale, but it does answer your question, too. See "How do I create multiple views on one document?" in there.

Though they're both out of print since Wrox went out of business, I'll refer you to my books:

Professional MFC With Visual C++ 6.0
Professional MFC With Visual C++ 5.0
 
As an Amazon Associate, HardForum may earn from qualifying purchases.
Okay.. here's my question

how can i just send something out to get displayed on the rish control??

as of right now.. i cna type into it..but what if i want a line of text to appear?


like i want to put a string together off some other event.. and just have it appear on the rich text control..

how would i go about doing that?

thanks
 
I dont anything about mfc, but with the api you would just send the control a message, looking through msdn seems like WM_SETTEXT will do it, Where wParam is nothing and lParam is your string.

(Edited out wParam value, was looking at em_settextsomething which has extra utility settext doesnt use wParam.)
 
okay. i just tried it.. but i get garbage to come out.. instead of the string i want to come out.. :(

Code:
CString message = "I hate life";
	CString* m;

	m = &message;

	SendMessage(WM_SETTEXT ,0,LPARAM(m));

that is what i tried

and it seems to erase everything else that has been typed... bleh i hate school
 
In the winapi you must specify the window handle (in this case the rich edit handle) as the first parameter. MFC may be different, but it has to know where to send it somehow im sure. And im assuming CString is a normal null terminated string.

Code:
LRESULT SendMessage(          HWND hWnd,
    UINT Msg,
    WPARAM wParam,
    LPARAM lParam
);

Edit: Let me google around a bit to figure out enough about mfc to analyze whats going wrong =)
(Seems ur sendmessage is part of a window class)
 
RancidWAnnaRIot said:
okay. i just tried it.. but i get garbage to come out.. instead of the string i want to come out.. :(

Code:
CString message = "I hate life";
	CString* m;

	m = &message;

	SendMessage(WM_SETTEXT ,0,LPARAM(m));

that is what i tried

and it seems to erase everything else that has been typed... bleh i hate school

Your code isn't correct. Your problem isn't the rich edit control; it's pointers. For this functionality, you've got no reason to take the address of that CString object, or use a pointer to a CString in the first place.

Here's what I would code if I wanted to use SendMessage():
Code:
	CString message = "I hate life";
	SendMessage(WM_SETTEXT ,0, (LPARAM) (LPCTSTR) m);

Of course, since you're using MFC, you've got no reason to use SendMessage. If you're setting plain text, just use the SetWindowText() member of CRichEditCtrl.
 
Yeah you're right he needs to dereference the m as it is sending the pointers address and not the strings address. I might need to pick up an MFC book one of these days, although I doubt I'll have the motivation to get through it.

Edit: Btw rancid what class are you taking thats teaching you mfc?
 
thanks for the help...

i really don't know what i'm doing here.. this is really stressing me out.. bleh.. i hate life.. i got sooo much other work to do as well.. i don't know.. it just doens't make sense to me.. :(



I wish i neve signed up for this class.. gawd i regret it sooo much
 
Are you not seeing my notes? It's a little annoying to go out of my way to try and help you when you don't offer any concrete acknowledgement that you're even paying attention.

So, here's my last stab at it:

There's more than twenty pages in my book devoted to working the control. Looks like you can get a copy of the book for about fifty cents, plus shipping, from amazon.com.

You can also look at the WordPad sample. WordPad, the applet that ships with Windows, was written in MFC and the source code for it is included in the MFC samples.

Good luck!
 
mikeblas said:
Are you not seeing my notes? It's a little annoying to go out of my way to try and help you when you don't offer any concrete acknowledgement that you're even paying attention.

So, here's my last stab at it:

There's more than twenty pages in my book devoted to working the control. Looks like you can get a copy of the book for about fifty cents, plus shipping, from amazon.com.

You can also look at the WordPad sample. WordPad, the applet that ships with Windows, was written in MFC and the source code for it is included in the MFC samples.

Good luck!


i tried what you posted above.. it prints out text, but i can't change the color or the font using rtf tags. i just get a bunch of garbage. i guess i'm not using the tabs right, but i don't know what's wrong with it

what's the name of your book?
 
RancidWAnnaRIot said:
i tried what you posted above.. it prints out text, but i can't change the color or the font using rtf tags. i just get a bunch of garbage. i guess i'm not using the tabs right, but i don't know what's wrong with it

what's the name of your book?

For the name of my book, please see Post #8 in this thread.

Tried what? Looking at the source for the WordPad sample? Fixing your code so that it wasn't broken?

If you want to programatically set colors, you just make a selection then set the font attributes. Make a selection by calling the SetSel() method. Change the font attributes by calling the SetSelectionCharFormat(). These functions are very well documented in MSDN; you can look them up by name.
 
Back
Top