Click here to Skip to main content
15,867,964 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
the message EM_FINDTEXTW posted to "rich_text_edit_control" is not working if i set updirection in flag parameter WPARAM.in my application,
Vice versa if i set FR_DOWN bit in flag everything is working fine

Notes:
"this->Window()" is the HWND of the main form.
richedit is the HWND of the rich_text_edit_control (a child of this->Window() ).


the message uFindReplaceMsg is tied up to FindTextA api

uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);

std::string selectedtext;
is std::string member of
MainWindow
class in which is stored the text to find
static FINDTEXT findtext;
//it is a structure locale to the
class MainWindow
msdn api needs it for the search funcionality

What I have tried:

LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
<pre>	tagFINDREPLACEA *p;
	if (uMsg == uFindReplaceMsg)//i used FindTextA msdn api to set the text and direction this is the managing at the closing of the FindTextA popup 
	{
		p = (tagFINDREPLACEA *)lParam;

		this->selectedtext.assign(p->lpstrFindWhat);

		this->findSelectedText( p->Flags);
		return 0;
	}



}

void  MainWindow::findSelectedText (int flag)
{
	int n = 0, rt, riga;

	TCHAR aa[64];

	if (this->selectedtext.compare(this->activeseltext) != 0 && this->selectedtext.length())
	{

		findtext.chrg.cpMin = 0;
		findtext.chrg.cpMax = -1;
		this->activeseltext.assign(this->selectedtext.c_str());
	}
	wcscpy(aa, to_wstring(this->selectedtext).c_str());


	if ( flag & FR_DOWN)
	{
		this->findtext.chrg.cpMin = findtext.chrg.cpMax + 1;
		this->findtext.chrg.cpMax = -1;
	}
	else
	{
	

		this->findtext.chrg.cpMax = this->findtext.chrg.cpMin;
		this->findtext.chrg.cpMin = 0;


		
	}
	                      
	n = SendMessage(richedit, EM_FINDTEXTW, (WPARAM)flag, (LPARAM)&findtext);

	if (n > 0)
	{
		findtext.chrg.cpMin = n;

		findtext.chrg.cpMax = n + wcslen(to_wstring(this->selectedtext).c_str());
		riga = SendMessage(richedit, EM_EXLINEFROMCHAR, 0, n);
		SetWindowText(this->Window(), std::to_wstring(n).c_str());


		SendMessage(richedit, EM_EXSETSEL, 0, (LPARAM)&findtext.chrg);//i am moving the selection to the point found 
		SendMessage(richedit, EM_HIDESELECTION, (LPARAM)FALSE, 0);


	}
	else
	{
		std::wstring aa(L"Passed End Of File ");
		if (flag & FR_DOWN)
			aa.append(L"DOWN dir");
		else
		{
			aa.append(L"UP dir ");
			aa.append(std::to_wstring(findtext.chrg.cpMax));
			aa.append(L" ");
			aa.append(std::to_wstring(findtext.chrg.cpMin));
		}
		MessageBox(this->Window(), to_wstring(this->selectedtext).c_str(), aa.c_str(), MB_ICONEXCLAMATION | MB_APPLMODAL);

	}

}
Posted
Updated 17-Oct-22 23:49pm
v23
Comments
Richard Deeming 18-Oct-22 5:14am    
If you're going to keep editing your question, at least have the decency to format your code properly! Either put your code inside the <pre> tags, or select the entire code block and click the "code" button on the editor toolbar.
Giovanni 2022 18-Oct-22 5:55am    
Sorry, I'm new to the environment

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

  Print Answers RSS


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