为什么EM_FINDTEXTEX消息总是返回零(win32)? [英] Why EM_FINDTEXTEX message is always returning a zero(win32)?

查看:204
本文介绍了为什么EM_FINDTEXTEX消息总是返回零(win32)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在丰富的编辑控件中搜索单词,并且我使用了EM_FINDTEXTW消息。但即使编辑框中有特定的单词,也总是返回零。为什么会这样?



I want to search for words in a rich edit control and i used the EM_FINDTEXTW message for the purpose. but it is always returning zero even if the particular word is there in the edit box.. Why is it so?

// i have created the edit control using the below code 
LoadLibrary("Msftedit.dll");
	HWND hEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE,
		"RICHEDIT50W",
		"My Rich Edit",
		WS_VISIBLE | WS_BORDER |
		WS_CHILD |
		ES_MULTILINE | WS_EX_RIGHTSCROLLBAR | WS_VSCROLL | WS_SIZEBOX,
		500, 30,
		500, 500,
		hMAin,
		0,
		GetModuleHandle(NULL),
		NULL);
SetWindowText(hEdit2, buffer);


//searching for a particular word
FINDTEXTEX ft;
	CHARRANGE ch;
	ch.cpMin = 0;
	ch.cpMax = -1;
	ft.chrg = ch;
	ft.lpstrText = m_szWord;
	int nIndex = SendMessage(hEdit2 , EM_FINDTEXTEX, FR_WHOLEWORD, (LPARAM)&ft);
	CString s;
	s.Format("%d", nIndex);
	MessageBox(hMAin, s, "", NULL);





m_szWord包含我要在编辑框中搜索的单词。 MessageBox总是显示零值。

请帮助..



m_szWord contains the word i want to search in the edit box. MessageBox always shows the value zero.
Please Help..

推荐答案

我测试了下面的代码及其工作原理。比较你的错误



I tested below code and its working. Compare what is wrong at your end

LoadLibrary(L"Msftedit.dll");

hEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE,
   L"RICHEDIT50W",
   L"My Rich Edit",
   WS_VISIBLE | WS_BORDER |
   WS_CHILD |
   ES_MULTILINE | WS_EX_RIGHTSCROLLBAR | WS_VSCROLL | WS_SIZEBOX,
   500, 30,
   500, 500,
   hWnd,
   0,
   GetModuleHandle(NULL),
   NULL);
   SetWindowText(hEdit2, L"This is Hello World");

   FINDTEXTEX ft;

   CHARRANGE ch;
   ch.cpMin = 0;
   ch.cpMax = -1;
   ft.chrg = ch;
   ft.lpstrText = L"Hello";
   nIndex = SendMessage(hEdit2 , EM_FINDTEXTEX, FR_DOWN, (LPARAM)&ft);


这篇关于为什么EM_FINDTEXTEX消息总是返回零(win32)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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