|
강병우 님이 쓰신 글 :
: 메모나 리치에디트에서 FindDialog를 이용해서 찾는건 쉬운데요..
: 문제가 있네요.
:
: 화면에 없는 Text를 찾을때 찾은문자열이 메모장 화면에 있어야 하는데 Cursor가 그쪽으로 안갑니다.
: 이거 어케 해결하나요?
:
: 예제를 찾아봐도 안나와있어서리.. 누가 아는사람없나요..
:
: 찾은 문자열이 있으면 그 문자열이 있는부분으로 자동으로 이동하게 하는 방법을 알고 계신분 제발 좀 갈켜 주세요..
:
임펠리테리입니다.
빌더의 헬프에 있는 예제대로 다음과 같이 하셨겠죠?
void __fastcall TForm1::FindDialog1Find(TObject *Sender)
{
int FoundAt, StartPos, ToEnd;
// begin the search after the current selection
// if there is one
// otherwise, begin at the start of the text
if (RichEdit1->SelLength)
StartPos = RichEdit1->SelStart + RichEdit1->SelLength;
else
StartPos = 0;
// ToEnd is the length from StartPos
// to the end of the text in the rich edit control
ToEnd = RichEdit1->Text.Length() - StartPos;
FoundAt = RichEdit1->FindText(FindDialog1->FindText, StartPos, ToEnd, TSearchTypes()<< stMatchCase);
if (FoundAt != -1)
{
RichEdit1->SetFocus();
RichEdit1->SelStart = FoundAt;
RichEdit1->SelLength = FindDialog1->FindText.Length();
}
}
그런데 이렇게 해도, 찾은 텍스트를 선택은 해줍니다만 자동으로 선택된 텍스트가 보이도록 스크롤되진 않습니다. 이때는 EM_SCROLLCARET 메시지를 이용하면 됩니다. 이 메시지는 현재 커서의 위치로 스크롤시키는 역할을 합니다.
앞에서와 같이 작성한 코드의 마지막에 다음과 같은 한 라인을 추가하세요.
SendMessage(RichEdit1->Handle, EM_SCROLLCARET, 0, 0);
그럼 참고하시길...
|