Solved

capturing visible CRichEditView area text???

Posted on 1998-02-15
6
218 Views
Last Modified: 2013-11-20
How do I capture the CRichEditView visible client text area
...not the text that needs to be scrolled to.. I could use
the SelSel() function if I could aquire the co-ordinates for
the visible text .. But how do I aquire these co-ordinates..
0
Comment
Question by:simlox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 1316208
The coordinates of the client area area available by calling CRichEditView::GetClientRect().  It's just like any other window.

Or did you mean that you wanted to get the text that's visible in the control, and not all of the text in the control? You can do that by:

1) Calling GetClientRect() to get the client rectangle
2) Calling CharFromPos() on the top-left and bottom-right coordinates in the client rectangle.
3) Calling GetTextRange() using the character indexes you got from step #2.

That's that.

.B ekiM

0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1316209
And, what was wrong with those answers? CharFromPos() is the function you said you were looking for.

.B ekiM


0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1316210
Ooop! GetTextRange() isn't provided by any of the shipping versions of MFC. You'll need to use the EM_GETTEXTRANGE message directly. If you want to get the characters from nStart to nStop, you can use:

CString str;
LPTSTR pstr = str.GetBufferSetLength(nStop - nStart + 2);
TEXTRANGE textRange;
textRange.chrg.cpMin = nStop;
textRange.chrg.cpMax = nStart;
int nCopied = SendMessage(EM_GETTEXTRANGE, 0, (LPARAM) &textRange);
str.ReleaseBuffer(nCopied);

// result in str;

.B ekiM
 

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:simlox
ID: 1316211
I have included the function I composed, I've had to use the
CEdit controls version of CharFromPos() as there is none available in the CRichEditView/ctrl class.. I am using visual C++
version 5 (visual studio 97) purchased in april 97...
The function below returns -1 from the CharFromPos() and return
blank from the string str... Could somebody please have a look
to see the problem..

void CProjEditorView::OnRectText()
{
      /* Get only the text that is visible in the control
            not all the text in the control */
      CString str;
      RECT mRect = {0,0,0,0};
      RECT Temp = {0,0,0,0};
      CEdit* mEdit = new CEdit(); // create cedit as CharFromPos()
                                                // is not a CRichTextView class
                                                // member
      mEdit->Create(WS_DISABLED,Temp,this,0);
      CRichEditView::GetClientRect(&mRect);
      CPoint mPoint;      // used for co-ordinates

      mPoint.x = mRect.top; // set top-left
      mPoint.y = mRect.left;
      int intedit1 = mEdit->CharFromPos(mPoint); //get pos in stream
      mPoint.x = mRect.bottom; // set bottom-right
      mPoint.y = mRect.right;
      int intedit2 = mEdit->CharFromPos(mPoint); // get pos in stream
      // intedit1 and intedit2 are always -1
      LPTSTR pstr = str.GetBufferSetLength(mPoint.y -
            mPoint.x + 2);
      TEXTRANGE textrange;
      textrange.chrg.cpMin = mPoint.y;
      textrange.chrg.cpMax = mPoint.x;
      int nCopied = SendMessage(EM_GETTEXTRANGE,0,
            (LPARAM)&textrange);
      str.ReleaseBuffer(nCopied);
      // str is always empty .. is it because I am using a CEdit
      // control that is empty;
}

0
 
LVL 11

Accepted Solution

by:
mikeblas earned 100 total points
ID: 1316212
// Welp, I guess I'll write the whole thing for you.
// Also, make sure you're not falling victim to the bug described in
// KB article Q137249

   CRichEditCtrl& theCtrl = GetRichEditCtrl();

   CRect mRect;
   theCtrl.GetClientRect(&mRect);

   POINT pts;
   pts.x = mRect.left+1;
   pts.y = mRect.top+1;
   int intedit1 = theCtrl.SendMessage(EM_CHARFROMPOS, 0, (LPARAM) &pts);

   pts.x = mRect.right - 1;
   pts.y = mRect.bottom - 1;
   int intedit2 = theCtrl.SendMessage(EM_CHARFROMPOS, 0, (LPARAM) &pts);

   CString str;
   ASSERT(intedit1 <= intedit2);      
   LPTSTR pstr = str.GetBufferSetLength(intedit2 - intedit1 + 1);

   TEXTRANGE textrange;
   textrange.chrg.cpMin = intedit1;
   textrange.chrg.cpMax = intedit2;
   textrange.lpstrText = pstr;
   int nCopied = theCtrl.SendMessage(EM_GETTEXTRANGE, 0, (LPARAM) &textrange);
   str.ReleaseBuffer(nCopied);

   MessageBox(str);

0
 

Author Comment

by:simlox
ID: 1316213
Thanks for your help..
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 58
Macro to save highlighted rows as a separate file 5 46
mapAB Challlenge 35 174
wordappend challenge 8 223
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question