This Chunk of code, isolated for posterity's sake.

This piece, courtesy of Rob, implements simple drag/drop detection on MOST controls within WIn32::GUI, notably Treeview/Listview/Listbox. There are underlying support procedure in place for handling the "candy" side of things such as CreateDragImage in Treeview.

Please note, that while portions CAN be implemented in OEM, they are done here using the NEM model, which has per experience (personally myself) provided a more accurate functionality to the desired result.

Jason P.

PS - hopefully shortly I will find the time to send an implementation of this in regad to the Treeview control, that I simply haven't had the spare time prep for general use.

- spawned from [While Mouse Down, Move Window]
(1) Using mouse down/move/up:

#!perl -w
use strict;
use warnings;

use Win32::GUI;

my $down   = 0; # Flag to indcate if we are dragging or not
my $msx;       # last known position of mouse in screen co-ordinates
my $msy;       # last known position of mouse in screen co-ordinates

my $mw = Win32::GUI::Window->new(
       -title => "Click anywhere to move",
       -pos   => [100,100],
       -size  => [400,300],
       -onMouseDown => \&down,
       -onMouseUp   => \&up,
       -onMouseMove => \&move,
);

$mw->Show();
Win32::GUI::Dialog();
exit(0);

sub down
{
       my ($object, $x, $y) = @_;

       # we're dragging
       $down = 1;

       # record mouse position
       ($msx, $msy) = $object->ClientToScreen($x, $y);

       # capture mouse
       $object->SetCapture();

       return 1;
}

sub up
{
       my ($object) = @_;

       # not dragging any more
       $down = 0;

       # release mouse capture
       $object->ReleaseCapture();

       return 1;
}

sub move
{
       my ($object, $x, $y) = @_;  # x/y in client co-ordinates

       # don't do anything unless the left button is down
       return unless $down;

       # how much have we moved?
       my ($sx, $sy) = $object->ClientToScreen($x, $y);
       my $xshift = $sx - $msx;
       my $yshift = $sy - $msy;

       # record the new mouse position
       ($msx, $msy) = ($sx, $sy);

       # move the window
       $object->Move($object->Left() + $xshift, $object->Top() + $yshift);

       return 1;
}
__END__

Regards,
Rob.



Reply via email to