Solved

capturing visible CRichEditView area text???

Posted on 1998-02-15
6
216 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 35
Include multiple hostnames in this command? 3 55
windows 10 how make picture as desktop background 2 62
mapBully challenge 6 134
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 …
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

773 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