Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
win32 RichEdit control supports large count of words. i'm tring to find some string in this kind of control. I find the win32 message
EM_FINDTEXT
on msdn. if the spfecified string was found , the return value would be the index of the control's text.

I tried,but it does not work.

What I have tried:

here is some simple codes.

int result = 0;
FINDTEXT findtext_param;

RichEdit1->Text = "Hello,this is a test from younth.";

char find_str[256] = "from";
findtext_param.lpstrText = find_str;
findtext_param.chrg.cpMin = 0;
findtext_param.chrg.cpMax = -1;

result = SendMessage(RichEdit1->Handle,EM_FINDTEXT,FR_DOWN,(LPARAM)&findtext_param);
if(result >= 0) ShowMessage("string found.");
else ShowMessage("string not found.");


you can see the value of the control has been setted,it still returns -1.
what's wrong in the code ?
Posted
Updated 19-Sep-18 0:15am

1 solution

You need to select your range first:

C++
int result = 0;
FINDTEXT findtext_param;

RichEdit1->Text = "Hello,this is a test from younth.";

char find_str[256] = "from";
findtext_param.lpstrText = find_str;
findtext_param.chrg.cpMin = 0;
findtext_param.chrg.cpMax = -1;

// Missing this part
	CHARRANGE cr;
	cr.cpMin = -1;
	cr.cpMax = -1;

	SendMessage(RichEdit1->Handle, EM_EXSETSEL, 0, (LPARAM)&cr);
// <--

result = SendMessage(RichEdit1->Handle,EM_FINDTEXT,FR_DOWN,(LPARAM)&findtext_param);
if(result >= 0) ShowMessage("string found.");
else ShowMessage("string not found.");
 
Share this answer
 
Comments
Yount_0701 19-Sep-18 8:02am    
I tried your code , it just not work.Is there anything wrong ?
Leo Chapiro 19-Sep-18 8:18am    
Take a look at this example: Add a RichEdit to your app! (non-MFC) and check what you are missing else.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900