• Advertisement

Archived

This topic is now archived and is closed to further replies.

Finding line the cursor is over in an edit control

This topic is 5993 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a CRichEditCtrl and i need to find out what line the mouse cursor is hovering over. The user will be dragging icons onto the rich edit ctrl and when the user releases the mouse button to drop the icon, i need to add a string to the beginning of the line that the user dropped the icon on to, but i cant find any way of figuring out what line the user was over when he dropped the icon. Anyone got any ideas? Thanks for any help Edit-Ive just reread your reply Mayrel and realised you were offering 2 things (i originally missed the CharFromPos part). And yes it looks like that my solution lies there, however i am doing: //REpt is the point the cursor is on POINTL* lpPoint=new POINTL; lpPoint->x=REpt.x; lpPoint->y=REpt.y; DWORD CharIndex=SendMessage(EM_CHARFROMPOS,0, (LPARAM) (POINTL *)lpPoint); but the send message always returns 0. Any idea what im doing wrong? Thanks very much Edited by - Zeke on November 22, 2001 10:22:41 AM

Share this post


Link to post
Share on other sites
Advertisement
I think that a combination of EM_CHARFROMPOS and EM_LINEFROMCHAR should do what you want.

Aha. CRichEditCtrl has a LineFromChar member, so you don't have to use EM_LINEFROMCHAR directly. I couldn't find any equivalent to EM_CHARFROMPOS, though.

All your bases belong to us (I know. It's irony.)

Edit: Added LineFromChar

Edited by - Mayrel on November 22, 2001 9:12:37 AM

Share this post


Link to post
Share on other sites
Thanks for the reply but I cant use LineFromChar because I dont know the character index to pass in to LineFromChar().

The character index to pass in to it will be the character that the mouse cursor (not the caret) is hovering over (when the user drops the icon) and this character index or the line is what i need to find out from the position of the mouse cursor (again not the caret because the caret wont be in the correct position).

To try and clarify my problem ill offer this example. The user has loaded some text into the edit control:

BARNARDO
Who''s there?

FRANCISCO
Nay, answer me. Stand and unfold yourself.

BARNARDO
Long live the king!

FRANCISCO
Barnardo?

BARNARDO
He.

and wants to drag an mp3 from a list box onto the text (so that when loaded into a seperate app it will be highlighted as a link to play the mp3). The user drags the mp3 he wants and drops it (releases the mouse button)on the first Barnardo. What I want my app to do then is add [Audio NameOfMp3]before the Barnardo that was dropped onto:

[Audio Barnardo1]BARNARDO
Who''s there?

FRANCISCO
Nay, answer me. Stand and unfold yourself.

But the problem is when the user drops the icon I have no way (that i know of) to get the line or character that the user dropped the mp3 on to, so I cant then add the string [Audio Barnardo1] to the beginning of that line.

This is proving to be a particularly annoying problem as I am now trying to find the line using twips and converting points into twips into lines and its just not working so if anyone has any idea at all id be very grateful.

Share this post


Link to post
Share on other sites
YES!! Got it. I was using CListBox::SendMessage() instead of CRichEditCtrl::SendMessage(). Now it works brilliantly. Thank you very much Mayrel I really appreciate it.

Share this post


Link to post
Share on other sites
quote:
Original post by Zeke
Thanks for the reply but I cant use LineFromChar because I dont know the character index to pass in to LineFromChar().


Use EM_CHARFROMPOS.

At a guess, you'd do something like:

      
int lineFromPoint (CRichEditCtrl *lpRichEditCtrl, LPPOINT lpPoint) {
int iCharPos = lpRichEditCtrl->SendMessage(EM_CHARFROMPOS, 0, (WPARAM) lpPoint);
return lpRichEditCtrl->LineFromChar(iCharPos);
}


quote:

BARNARDO
Who's there?

FRANCISCO
Nay, answer me. Stand and unfold yourself.

BARNARDO
Long live the king!

FRANCISCO
Barnardo?

BARNARDO
He.


Hehe. Cool.

Abolish Software Patents! | freepatents | lpf

Edit: Typo (and again)

Edited by - Mayrel on November 22, 2001 10:37:59 AM

Share this post


Link to post
Share on other sites
quote:
Original post by Zeke
YES!! Got it. I was using CListBox::SendMessage() instead of CRichEditCtrl::SendMessage(). Now it works brilliantly. Thank you very much Mayrel I really appreciate it.


Excellent! Now there''s just the little matter of the price... Your immortal soul! Muahahahahahahaha! Muahahahahahahaha!

*is carted away by men in white coats*

Abolish Software Patents! | freepatents | lpf

Share this post


Link to post
Share on other sites
For solving this problem for me you can have my immortal soul cos id totally run out of ideas lol.

Thanks again

Share this post


Link to post
Share on other sites

  • Advertisement