Solved

capturing visible CRichEditView area text???

Posted on 1998-02-15
6
221 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

Industry Leaders: 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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 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