tomsell has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

Trawling the 'Net didn't turn up anything, so I'd like to ask this seemingly simple question:

After placing the caret/cursor in a Win32::GUI RichEdit control, how do I determine its absolute position, i.e the offset relative to the beginning of the entire buffer? I.e. what the emacs lisp (point) function returns.

GetSel() is meaningful only when there's a selection. And chaining GetCursorPos(), ScreenToClient() and CharFromPos() won't help.

Replies are listed 'Best First'.
Re: Win32::GUI RichEdit: get absolute cursor position
by BrowserUk (Patriarch) on Aug 08, 2012 at 18:21 UTC

    The call you want is GetCaretPos().

    I've no idea if Win32::GUI exposes that api -- nor even how you would go about finding out from the horrible docs they provide -- but I know it is exposed by Win32::GuiTest and that should give you what you need.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Thanks for pointing out Win32::GuiTest which complements Win32::GUI quite nicely though GetCaretPos() comes up kinda empty.

      Anyway, the problem turned out to be my use of the wrong event handler. onMouseDown made GetSel() return erratic values. Asking GetSel() in the context of onMouseUp always returns the correct value for the insertion point.

      Win32::GUI docs: yeah, best to read the XS and MSDN...