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)
{
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);
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);
}
}