http://www.perlmonks.org?node_id=1017597


in reply to Win32::GUI::Richedit strange results for deselecting a selection

within the selection: although the text ist deselected, querying the control still returns the values of the old selection, which is NOT OK!

I see that too, but it doesn't seem to strange to me, since your mouse handler (callback) is being called before the selection change is registered, before the selection range is updated, before the selchange event is generated

You should be binding to a "SelChange" event , but you can't
Rich Edit (Windows)
EN_SELCHANGE notification code (Windows)
I would use Wx

  • Comment on Re: Win32::GUI::Richedit strange results for deselecting a selection (events)

Replies are listed 'Best First'.
Re^2: Win32::GUI::Richedit strange results for deselecting a selection (events)
by tomsell (Acolyte) on Apr 08, 2013 at 20:14 UTC

    (just now came across my post through a Google search, ... here's the solution for completeness sake)

    "SelChange" event: quite right! That's what hooks are for.

    $myRichEdit->Hook(EN_SELCHANGE, \&SelChangeEvents_Handler); sub SelChangeEvents_Handler { my ($object, $wParam, $lParam, $type, $msgcode) = @_; return unless($type == WM_NOTIFY); return unless($msgcode == EN_SELCHANGE); my ($hwndFrom, $idFrom, $code, $cpMin, $cpMax, $seltyp) = unpack("LLLLLL", unpack("P24", pack("L", $lParam))); return unless($hwndFrom == $object->{-handle}); my $haveSelection = ($cpMin != $cpMax); if($haveSelection){ print STDERR " we have a selection!"; } }