Link to home
Start Free TrialLog in
Avatar of Mournblade
Mournblade

asked on

Trying to indent text in CRichEditCtrl

I am trying to make a CRichEditCtrl indent lines in the control a set number of spaces. If the window is resized, the indents stay.  (What I really need is to be able to indent selected lines, such as those without a preceding newline char, and not indent others.)  But I can't even get part A to work yet.  I've tried SetParaFormat(), but with no luck.  And I'm not sure if this really does what I want.  I've seen it done smoothly in other apps, so I'm sure it's out there somewhere....

Thanks!
Avatar of mikeblas
mikeblas


So, you want the first line of the paragraph to be indented more than the rest of the paragraph, right?  Like this:

       blah blah blah blah
   blah blah blah blah blah
   blah blah blah blah blah

That's called a first line indent, it's pretty esay to set up.

You need to set a negative value for the offset and a positive value for the indent.  The value for dxStartIndent is going to be the number of twips for the first line.  The dxOffset needs to be the different between the indentation for the first line and the rest.

These measurements are all in twips, so on inch is 1440 units.

You'd set up the structure like this:

   PARAFORMAT pf;
   pf.cbSize = sizeof(pf);
   pf.wNumbering = 0;
   pf.wReserved = 0;
   pf.dxStartIndent = 1440;
   pf.dxRightIndent = 0;
   pf.wAlignment = PFA_LEFT;
   pf.cTabCount = 0;
   pf.dwMask = PFM_OFFSET | PFM_ALIGNMENT | PFM_RIGHTINDENT | PFM_STARTINDENT;

And that'll do it!

..B ekiM
Avatar of Mournblade

ASKER

I have not actually rejected this answer.  I just wanted to write a comment real quick, and I don't yet have time to test this.

I actually want the opposite, like this:

blah blah blah blah
    blah blah blah blah
    blah blah blah blah

though i doubt that matters much.  Also, I want everything in the control to come out like this- is this a 'paragraph', or something else?

Talk to you again soon...
Ok, I've tested it.  You've got to be kidding!  First-why is this done only in twips?  Second, I cannot get it to do anything even close to what I want.  It will indent only at 1440 (and then way more than an inch - though this may merely be dependent on my display settings), and it indents ALL lines.  I cannot get it to distinguish a beginning line.  And what makes up a "beginning" line, anyway?  And why does the MFC documentation, which is basically nonexistant, assume we know what defines these "paragraphs", etc?  "Paragraph?"  Huh?

Frustrating...  but thanks anyhow.  
> You've got to be kidding!  

I'm not kidding at all. Why do you need to insult my efforts to help you?

 > First-why is this done only in twips?  

Because that's a standard unit of measure for publishing and page layout disciplines.

 > though this may merely be dependent on my display settings

Yes, it is. What constitues a physical inch on a display device is dependent on a couple of different ratios. You can make it work, but it requires very careful setup--which almost nobody ever does.

 > And what makes up a "beginning" line, anyway?  

The beginning line is the first line of the paragraph. A paragraph is a block of text that ends with a paragraph marker. The rich edit control uses a carriage-return to mark the end of a paragraph.

To do a hanging indent, like you've asked for, you'll need a structure like this:

   PARAFORMAT pf;
   pf.cbSize = sizeof(pf);
   pf.wNumbering = 0;
   pf.wReserved = 0;
   pf.dxStartIndent = 0;
   pf.dxOffset = 1440;
   pf.dxRightIndent = 0;
   pf.wAlignment = PFA_LEFT;
   pf.cTabCount = 0;
   pf.dwMask = PFM_OFFSET | PFM_ALIGNMENT | PFM_RIGHTINDENT | PFM_STARTINDENT;

 > Also, I want everything in the control to come out like this-
 > is this a 'paragraph', or something else?

You'll need to apply the above paragraph formatting to everything in your control.

Do you want me to write a complete application for you as a sample?

..B ekiM
> And why does the MFC documentation, which is basically nonexistant,
 > assume we know what defines these "paragraphs", etc?  

As the documentation itself states, you can send feedback to the docs team directly at vcdocs@microsoft.com .

Also, I just noticed that my first posting (for the first-line indented style you didn't want) is incorrect. It's missing a setting for the dxOffset member, which should be -1440.

..B ekiM
No, I'm not kidding.  I was referring to the ridiculousness of the ParaFormat and its documentation in MFC.  If you took that as an insult, it's only your insecurity.  And I asked "why is it ONLY in twips" - which you didn't answer.  I could go on a little bit here, but I don't have the time.  I would have thanked you for your efforts, but your final sentence here earned you the zero.

Thank you for your efforts.

Not to mention that your answer didn't even do what you said it would.   You noticed this.  It was no big deal, but anyhow...
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial