在unicode应用程序中与CrichEditCtrl :: FindText()的问题 [英] Issue with CrichEditCtrl ::FindText() in unicode app

查看:73
本文介绍了在unicode应用程序中与CrichEditCtrl :: FindText()的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正面临与使用CrichEditCtrl进行文本搜索相关的一些问题 在unicode app ..


CRichEditCtrl * pvoEditCtrl;

//在这里加载文字

{

  ///////

}


CString strFindWhat = _T(" Hello");


FINDTEXTEX FindText; 

DWORD      dwSearchFlags;

       

//案例1:正常搜索

dwSearchFlags = 0 ;


FindText.chrg.cpMin = 0;

FindText.chrg.cpMax = -1;

FindText.lpstrText  =(LPCTSTR)pvstrFindWhat;  // FindText.lpstrText  =(LPSTR)(LPCTSTR)strFindWhat;对于非unicode应用程序ANSI


for(long lnCharPos = -1;((lnCharPos = pvoEditCtrl-> FindText(dwSearchFlags,& lvFindText))!= - 1); lnCount ++)

{

   //做某事

}


//案例2:全字匹配

dwSearchFlags = FR_WHOLEWORD;


FindText.chrg.cpMin = 0;

FindText.chrg.cpMax = -1;

FindText.lpstrText  =(LPCTSTR)pvstrFindWhat;
$
for(long lnCharPos = -1;((lvnCharPos = pvoEditCtrl-> FindText(dwSearchFlags,& lvFindText))!= - 1); lnCount ++)

{

  //做一些事情b
}




问题I发现如下:

案例1:它给出了 所有单词的所有行或字符位置 其中包含 搜索字符串的第一个字符串就像"H"一样。 "你好"在unicode应用程序中。

       它只为单词提供所有行或字符位置 其中包含 的 搜索字符串就像"Hello"一样在非unicode应用程序(ANSI)。

Csae 2:没有结果,找不到字符串,FindText()返回-1 用于unicode应用。

       非unicode应用程序(ANSI)的正确结果。


此API FindText()有什么问题?


请帮我纠正问题。

解决方案

试试这个:


    FindText.lpstrText <跨度>&NBSP;
= pvstrFindWhat;


并更改 pvstrFindWhat <的定义/ em>到
LPCTSTR
LPTSTR TCHAR [] 并进行其他调整,以便它将保存Unicode字符串非Unicode应用程序中的Unicode应用程序和非Unicode字符串。删除类似
(LPCTSTR)的演员表,这些情况不适合。确保没有覆盖此特定文件设置的编译器选项。


使用常量 FD_DOWN 如果你想向前搜索。


作为临时解决方法,你也可以明确使用 FINDTEXTEXA
:: FindTextA ,或 FINDTEXTEXW :: FindTextW ,具体取决于
pvstrFindWhat。


Hi All,

I am facing some issue related to text search with CrichEditCtrl  in unicode app ..

CRichEditCtrl *pvoEditCtrl;
//Load text here
{
  ///////
}

CString strFindWhat = _T("Hello");

FINDTEXTEX FindText; 
DWORD      dwSearchFlags;
       
//case 1: Normal search
dwSearchFlags = 0;

FindText.chrg.cpMin = 0;
FindText.chrg.cpMax = -1;
FindText.lpstrText  = (LPCTSTR) pvstrFindWhat;  // FindText.lpstrText  = (LPSTR) (LPCTSTR) strFindWhat; for non unicode application ANSI

for( long lnCharPos = -1 ; ((lnCharPos = pvoEditCtrl->FindText(dwSearchFlags, &lvFindText)) != - 1); lnCount++)
{
   //do something
}

//Case 2: whole word match
dwSearchFlags = FR_WHOLEWORD;

FindText.chrg.cpMin = 0;
FindText.chrg.cpMax = -1;
FindText.lpstrText  = (LPCTSTR) pvstrFindWhat;
for( long lnCharPos = -1 ; ((lvnCharPos = pvoEditCtrl->FindText(dwSearchFlags, &lvFindText)) != - 1); lnCount++)
{
 //do something
}


Issues I found are following:
Case 1: It gives  all line or char position for all word  which contain  the first char of search string as like "H" of "Hello" in unicode application.
        It gives all line or char position for only word  which contain  the  search string as like "Hello" in non unicode application (ANSI).
Csae 2: No result, string not found, FindText() returns -1  for unicode application .
        Correct result for non unicode application (ANSI).

What is the issue with this API FindText() ?

Please help me to correct the issue.

解决方案

Try this:

    FindText.lpstrText  = pvstrFindWhat;

and change the definition of pvstrFindWhat to LPCTSTR, LPTSTR or TCHAR[] and make other adjustments, so that it will hold a Unicode strings in Unicode application and non-Unicode strings in non-Unicode application. Remove the casts like (LPCTSTR), which are not appropriate in such situations. Make sure that there are no compiler options that override the settings for this particular file.

Use the constant FD_DOWN if you want to search forward.

As a temporary workaround you can also use explicitly FINDTEXTEXA and ::FindTextA, or FINDTEXTEXW and ::FindTextW, depending on the kind of pvstrFindWhat.


这篇关于在unicode应用程序中与CrichEditCtrl :: FindText()的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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