Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting TMemo character position from mouse position

Status
Not open for further replies.

LejonO

Programmer
Oct 13, 2007
2
SE
I use Borland's TMemo textpad and want to know the character position of my mouse cursor in the Memo, so in MouseMove I do the following:

// X and Y are in client space
void __fastcall MyApp::Memo1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
TPoint mousePos;
mousePos.x = X;
mousePos.y = Y;
int charPos = SendMessage(Memo1->Handle, EM_CHARFROMPOS, 0, (LPARAM)&mousePos);
}

The problem is charPos is always -1, even when I move the mouse over text in the Memo. Any ides whats wrong?
 
I'm not possitive, but would a timer help?
Since it doesnt seem to update when you move it around.
Was a long time since I used c/c++ :)
 
I actually found out what was wrong, it doesn't seem to work with a Point, this is how it should look:

LRESULT charPos = SendMessage(Memo1->Handle, EM_CHARFROMPOS, 0, MAKELPARAM((WORD)X,(WORD)Y));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top