|
Question : using CRichEditCtrl::FindText ..
|
|
hi all!
I have build my own Find/Replace dialog ( derived from CDialog class) to search into a CRichEditCtrl . now, everything is working just fine except 1 thing: how can implement "direction up" option ?? I mean to search from the current position to the beginning of the document ?? .. FindText method can't do it ..
10x
|
|
Answer : using CRichEditCtrl::FindText ..
|
|
Here's an answer (AND IT's NOT PRETTY). :-(
The following code... ================================================ int n; m_edit.SetWindowText("When your mom is mad with your dad, don't let her brush your hair."); FINDTEXT range = {{0,0},"your"}; m_edit.SetSel(-1,-1); m_edit.GetSel(range.chrg); range.chrg.cpMax=0; while((n = m_edit.SendMessage(EM_FINDTEXT, 0, (LPARAM)&range))!=-1){ TRACE("text found at %d\n",n); range.chrg.cpMin = n; } =================================================== Produces the following output... text found at 56 text found at 26 text found at 5 =================================================== Indicating that indeed you can search backwards by swapping the cpMin & cpMax values around, BUT....
a) you can't use -1 to indicate the end of the file; and b) you can't use version 1.0 of the rich edit control. Because I created my Rich Edit control using the dialog resource editor I had to subsequently manually edit my .rc file as text and change this line CONTROL "",IDC_RICHEDIT,"RichEdit" ,ES_MULTILINE | WS_BORDER | WS_TABSTOP,39,26,116,83
to this CONTROL "",IDC_RICHEDIT1,"RichEdit20A" ,ES_MULTILINE | WS_BORDER |WS_TABSTOP,39,26,116,83
in order to be using version 2 of the rich text control. (Hint use Spy++ to check the class of your rich text window).
Cheers Greg
"RichEdit20A"
|
|
|
|