I am trying to find out the location of the pointer within a CRichEditCtrl without clicking within the control. I need to know the character index it is on, not just the coordinates of the pointer. To do this I'm calling
int charIndex = ::SendMessage(theCtrl, EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y));
from within the view's OnMouseMove() function, to convert the mouse position to a character index. theCtrl is the richeditctrl instance, and pt is a CPoint object that is based on the point passed into OnMouseMove, but might be a few pixels shifted (for a reason, but I won't bother explaining why unless someone needs to know.)
I get an access violation when I hit this code. Not every time, most often when I am in a part of the richeditctrl that I had to scroll down to get to, but also in places at the top if I go over them a few times. It will work a few times then give the access violation eventually.
Any ideas? Other ways to get the character index I'm pointing at without using this code?