Win32控件richedit,如何使用EM_FINDTEXT win32消息查找字符串 [英] Win32 control richedit, how to find string by using EM_FINDTEXT win32 messages

查看:270
本文介绍了Win32控件richedit,如何使用EM_FINDTEXT win32消息查找字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

win32 RichEdit控件支持大量单词。我想在这种控制中找到一些字符串。我在msdn上找到了win32消息

 EM_FINDTEXT 

。如果找到了spfecified字符串,则返回值将是控件文本的索引。



我试过了,但它不起作用。



我尝试了什么:



这里有一些简单的代码。



 int result = 0; 
FINDTEXT findtext_param;

RichEdit1-> Text =你好,这是来自你的测试。;

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(找到字符串。);
else ShowMessage(找不到字符串。);





你可以看到控件的值已经设置,它仍然返回-1。

代码中有什么问题?

解决方案

您需要先选择范围:



  int  result =  0 ; 
FINDTEXT findtext_param;

RichEdit1-> Text = 您好,这是来自younth的测试。< /跨度>;

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

// 缺少此部分
CHARRANGE cr;
cr.cpMin = - 1 ;
cr.cpMax = - 1 ;

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

result = SendMessage( RichEdit1->手柄,EM_FINDTEXT,FR_DOWN,(LPARAM)及findtext_param);
if (结果> = 0 )ShowMessage( 找到字符串。);
else ShowMessage( 找不到字符串。 );


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 ?

解决方案

You need to select your range first:

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.");


这篇关于Win32控件richedit,如何使用EM_FINDTEXT win32消息查找字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆