using CRichEditCtrl::FindText ..

hi all!

I have build my own Find/Replace dialog ( derived from CDialog class) to search into a CRichEditCtrl .
now, everything is working just fine except 1 thing: how can implement "direction up" option ?? I mean to search from the current position to the beginning of the document ?? .. FindText method can't do it ..

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The documentation on CRichEditCtrl::FindText says

Call this function to find text within the rich edit control. You can search either up or down by setting the proper range parameters in theCHARRANGE structure within the FINDTEXTEX structure.

I assume this means you just reverse the values of
cpMin & cpMax to search up.


dragoshAuthor Commented:
hi ggrundy

i've try that and it doesn't help ... in this way I set the range of text where to search , but NOT the "direction up" .. if I set cpMin = 0 and cMax let's say 1000 (current position) and click Find next I get the first match from the beginning of the document, not first match from current position ..

any ideas ??

Are you saying that you have tried

cpMin = nCurrentPosition;
cpMax = 0;

and it doesn't work???
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

dragoshAuthor Commented:
hi ggrundy

yes: it returns -1 ..
Here's an answer (AND IT's NOT PRETTY). :-(

The following code...
int n;
m_edit.SetWindowText("When your mom is mad with your dad, don't let her brush your hair.");
FINDTEXT range = {{0,0},"your"};
while((n = m_edit.SendMessage(EM_FINDTEXT, 0, (LPARAM)&range))!=-1){
  TRACE("text found at %d\n",n);
  range.chrg.cpMin = n;
Produces the following output...
text found at 56
text found at 26
text found at 5
Indicating that indeed you can search backwards by swapping the cpMin & cpMax values around, BUT....

a) you can't use -1 to indicate the end of the file; and
b) you can't use version 1.0 of the rich edit control.
Because I created my Rich Edit control using the dialog resource editor I had to subsequently manually edit my .rc file as text and change
this line

to this

in order to be using version 2 of the rich text control.
(Hint use Spy++ to check the class of your rich text window).

Cheers Greg


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dragoshAuthor Commented:
sorry about rejecting your answer ..

it works only with version 2 of rich text control ?
dragoshAuthor Commented:
hi again

in MSDN says about this .. in Rich Edit 2.0 or later - FR_DOWN etc.

i'am using CRichEditCtrl 1.0 , so that's way it doesn't work... i'll cosider to use 2.0

10x for your tips
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.