dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: CRichEditCtrl - margins and emdedded docs

  1. #1
    Join Date
    Mar 2002
    Location
    Chicago, IL
    Posts
    255

    CRichEditCtrl - margins and emdedded docs

    I have a CRichEditCtrl embedded on a dialog, and I'm filling it by loading up a RTF doc and streaming it into the control. Two questions:

    1) Is there a way I can embed the RTF document in the resources and have a CFile object open up the resource instead of providing an actual file system path?

    2) Is there a way to specify margins on the Rich Edit Control? Right now when the text is streamed into the control, it starts at the very top left. Ideally, I'd like a 10-15 pixel area of margin around the inside of the control.

    Thanks for any help!

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: CRichEditCtrl - margins and emdedded docs

    Re: 1, have you checked EM_STREAMIN. I am guessing you could send this message and in the callback pass in the buffer to the data.

    You could get the buffer by adding a resource to your exe and using LoadResource/LockResource to read the data into a buffer. Just a possibility.

  3. #3
    Join Date
    Mar 2002
    Location
    Chicago, IL
    Posts
    255

    Re: CRichEditCtrl - margins and emdedded docs

    I ended up finding a solution to both my question below through a little research. I'll post them here in case anyone had similar questions:

    1. I did pretty much what you were suggesting. I called FindResource, LoadResource, then LockResource. I got a void* back from LockResource which I then copied to the buffer in the "stream-in" callback using a CMemFile.

    2. I ended up using SetParaFormat on the Rich Edit Control. To set right and left margins, I selected all the text (SetSel(0, -1)), then called SetParaFormat using a PARAFORMAT2 object where I set the dxStartIndent and dxRightIndent. For the top margin, I selected the entire first line (SetSel(0, m_richEdit.LineLength(0)), then called SetParaFormat using a PARAFORMAT2 object where I set the dySpaceBefore.

    Thanks for your response.

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: CRichEditCtrl - margins and emdedded docs

    cool. Glad you worked it out. Thanks for sharing your solution

  5. #5
    Join Date
    Mar 2002
    Location
    Chicago, IL
    Posts
    255

    Re: CRichEditCtrl - margins and emdedded docs

    Actually, as I was reading the CRichEditCtrl documentation more closely, I found a way better solution for my second question (about setting margins). Instead of doing all that paragraph formatting, I called SetRect on my Rich Edit control with the client rect deflated by a few pixels. Much cleaner solution =)

  6. #6
    Join Date
    Nov 2018
    Posts
    1

    Re: CRichEditCtrl - margins and emdedded docs

    @sjc It is 2018, 10 years later and i have to say your answer helped me on your 2nd question.
    Here is a reference to SetRect which worked pretty well.. Thanks again
    https://docs.microsoft.com/en-us/cpp...s-2017#setrect

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)