Board index » cppbuilder » TRichEdit text under mouse?

TRichEdit text under mouse?


2005-10-18 12:30:27 AM
cppbuilder63
Is there any way to tell which character is under the mouse pointer in a
TRichEdit other than lots of math with fontheights and scrollbar positions
etc.?
 
 

Re:TRichEdit text under mouse?

Quote
Is there any way to tell which character is under
the mouse pointer in a TRichEdit other than lots
of math with fontheights and scrollbar positions etc.?

Look here maybe:
tinyurl.com/e4354
--
Best regards,
Vladimir Stefanovic
 

Re:TRichEdit text under mouse?

This could be the scratch:
void __fastcall TForm1::RichEdit1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
TPoint const PMouse = Point( X, Y );
int const char_index = SNDMSG( RichEdit1->Handle, EM_CHARFROMPOS, 0,
reinterpret_cast<LPARAM>(&PMouse) );
int const line_index = SNDMSG( RichEdit1->Handle, EM_EXLINEFROMCHAR, 0,
char_index );
int counter = 0;
for ( int i=0; i<=line_index-1; i++ )
counter += RichEdit1->Lines->Strings[i].Length() + 2;
int diff = char_index - counter;
Caption = IntToStr(line_index) + ":"+ IntToStr(diff);
}
By this, you get the X and Y position of the market char,
and further it's easy to determine the char
RichEdit1->Lines->Strings[line_index][diff];
... maybe you'll need extra try/catch to avoid exceptions...
--
Best regards,
Vladimir Stefanovic
 

{smallsort}

Re:TRichEdit text under mouse?

Thanks! That did the trick :)
(sorry for the email reply, hit the wrong button, darn outlook, someday i'll
have to get real newsgroup software :p)