Board index » Visual Studio » CrichEditCtrl Font and Clipoard related query

CrichEditCtrl Font and Clipoard related query

Visual Studio326
hi all,



I have a CRichEditCtrl created on CView derived class. After Creating

the Rich edit control it's default font is something different than

what i want. and it's bold also.



so to change the font i am selecting all the data present in control

and then applying new font to it.

(But This is not a very good method ).

but when i paste the data that is not compatible with mine font again i

need to select all the data and then apply font on it!!(Same thing

doing again)



so my question is that is there any way to change the clipboard data's

font so that my control will receive data in it's compatible font

only..



or is there any way that whatever font i want my rich edit control to

have

i should tell it before creation as some parameter..(i think this this

will be a good technique)

means if i want that my rich edit control should have only this font

say "courier new" and it is going to be fix for all it's lifetime then

i should create rich edit that starts with this font only and end's

with this font isn't it this sound well??



so is there any way to set the attributes of a control before even

creating it..



if anybody know's please reply..



Thanks and Regards

Harshal shete


-
 

Re:CrichEditCtrl Font and Clipoard related query



<harshalshete@gmail.com>wrote in message

Quote
hi all,



I have a CRichEditCtrl created on CView derived class. After Creating

the Rich edit control it's default font is something different than

what I want. and it's bold also.





I am not sure why you went to all that trouble when the CRichEditView

class has already been created for you.



Quote
so to change the font I am selecting all the data present in control

and then applying new font to it.

(But This is not a very good method ).

but when I paste the data that is not compatible with mine font again

I

need to select all the data and then apply font on it!!(Same thing

doing again)





How are you setting the font?



Quote
so my question is that is there any way to change the clipboard data's

font so that my control will receive data in it's compatible font

only..





The function CRichEditCtrl::Paste() simple pastes the text into the doc,

unformatted. You need to use PastSpecial if you want formatting.



Quote
or is there any way that whatever font I want my rich edit control to

have

I should tell it before creation as some parameter..(I think this this

will be a good technique)

means if I want that my rich edit control should have only this font

say "courier new" and it is going to be fix for all it's lifetime then

I should create rich edit that starts with this font only and end's

with this font isn't it this sound well??





For ansi text CF_TEXT is the text format for the clipboard data.

CF_OEMTEXT for the OEM character set. Both use a CR/LF to end the line

and a null character to mark the end of the data.



Quote
so is there any way to set the attributes of a control before even

creating it..





You could add a new CRichEditCtrl class and set the initial styles when

you create the your control. If you are using a view in either SDI or

MDI apps I recommend using the CRichEditView class for the view.







-

Re:CrichEditCtrl Font and Clipoard related query

I agree with Mark. There is no real need to do this. Either you want to use a

CRichEditView, or you might have some reason to use a CFormView with a rich edit control

in it. But hand-rolling your own has some risks.



First, to set the font, use SetFont to set the font you desire, before you put anything

into the control. When you create a control, it has NULL for the font reference, which

means "default to the system fault". It isn't actually bold, but it is a very large and

heavy font which is usually mistaken for a boldface font. But that's its normal weight.



This also explains why you get strange behavior on a paste; when you paste, it pastes it

with the default font for the control, which hasn't changed in any way just because you

selected some text and set the selected text to a particular font.



You would not change the font in the clipboard because the concept does not exist. There

is no font associated with the clipboard. If you put rich text into the clipboard, there

could be one or more fonts associated with the rich text, but that is encoded in the rich

text itself, and has nothing to do with the clipboard. The clipboard has no concept of

"font", only of "bits". If those bits happen to be flagged as rich-text format, then the

rich text control will read them in using the StreamIn method (or its underlying

implementation, actually) rather than just plunking them down, but you can't reach out and

change the contents in the clipboard without reading them out, parsing them, changing the

font information in the rich-text representation, and writing them back (don't forget to

write back ALL the formats which are stored in the clipboard!) This is, essentially,

impractical.



You can set a lot of attributes of a control AS you create it, and you can change some

AFTER you create it, but you can't change them BEFORE you create it. In your case, you

want to do a SetFont AFTER you create it. Note that you cannot specify the font of a

control before it is created, or AS it is created, but you can specify it AFTER it is

created.

joe



On 7 Oct 2006 01:10:53 -0700, "harshalshete@gmail.com" <harshalshete@gmail.com>wrote:



Quote
hi all,



I have a CRichEditCtrl created on CView derived class. After Creating

the Rich edit control it's default font is something different than

what i want. and it's bold also.



so to change the font i am selecting all the data present in control

and then applying new font to it.

(But This is not a very good method ).

but when i paste the data that is not compatible with mine font again i

need to select all the data and then apply font on it!!(Same thing

doing again)



so my question is that is there any way to change the clipboard data's

font so that my control will receive data in it's compatible font

only..



or is there any way that whatever font i want my rich edit control to

have

i should tell it before creation as some parameter..(i think this this

will be a good technique)

means if i want that my rich edit control should have only this font

say "courier new" and it is going to be fix for all it's lifetime then

i should create rich edit that starts with this font only and end's

with this font isn't it this sound well??



so is there any way to set the attributes of a control before even

creating it..



if anybody know's please reply..



Thanks and Regards

Harshal shete

Joseph M. Newcomer [MVP]

email: newcomer@flounder.com

Web: www.flounder.com">www.flounder.com

MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm

-