Solved

capturing visible CRichEditView area text???

Posted on 1998-02-15
6
213 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
  • 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now