[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

capturing visible CRichEditView area text???

Posted on 1998-02-15
6
Medium Priority
?
226 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 400 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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 …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

656 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