Translating Mouse Hit X Offset to Caret Position

Conventionally, the user can select caret position (cp) by clicking either the trailing half of character "cp-1" or the leading half of character "cp". An application can implement the translation of mouse hit x offset to caret position as follows:

int iCharPos;
int iCaretPos;
int fTrailing;
ScriptXtoCP(iMouseX, cChars, cGlyphs, pwLogClust, psva, piAdvance, psa,
            &iCharPos, &fTrailing);
iCaretPos = iCharPos + fTrailing;

For scripts that snap the caret to cluster boundaries, a call to ScriptXtoCP returns with fTrailing set to either 0 or the width of the cluster in code points.

Related topics

Using Uniscribe