2005/10/12, Robert May <[EMAIL PROTECTED]>:
> Jason P. wrote:
> > kortyzon wrote:
> >
> >> I'm a french win32 gui user and i search how to move the window
> >> whitout the dragbar.
> >>
> > you will need 3 things.
> >
> > mouseDown, mouseMove, mouseUp (these are generic names, the specifcs are
> > up to you in OEM/NEM)
> >
> > inside the mouseDown event, set a state flag (like $mouseIsDown)
> >
> > when the mouseMove event is fired, check the status of $mouseIsDown, and
> > then move the window accordingly.
> >
> > when mouseUp is fired, set $mouseIsDown to 0/-1/undef/your version of
> > false.
> >
> > viola.
> >
> > there may be some other slightly more specfic, but unmentioned code
> > realting to the exact method by which you know how and where to move the
> > window to, but these are the basics.
>
> Here's a (C++) article describing what you're looking for (see the
> second part of the article):
> http://msdn.microsoft.com/msdnmag/issues/02/12/CQA/default.aspx
>
> And because I wanted to understand the difference between then, here's
> Win32::GUI implementations of both methods:
>
> (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__
>
> (2) using WM_NCHITTEST:
>
> #!perl -w
> use strict;
> use warnings;
>
> use Win32::GUI;
>
> sub WM_NCHITTEST() {132}
> sub HTCAPTION()    {2}
>
> my $mw = Win32::GUI::Window->new(
>         -title => "Click anywhere to move",
>         -pos   => [100,100],
>         -size  => [400,300],
> );
>
> $mw->Hook(WM_NCHITTEST, \&hittest);
>
> $mw->Show();
> Win32::GUI::Dialog();
> exit(0);
>
> sub hittest
> {
>         my ($object, $wParam, $lParam, $type, $msgcode) = @_;
>
>         return unless $type == 0;
>         return unless $msgcode == WM_NCHITTEST;
>
>         # get mouse position from $lParam (screen co-ordinates)
>         my $sx = $lParam & 0xFFFF;
>         my $sy = ($lParam >> 16) & 0xFFFF;
>
>         # convert to client co-ordinates:
>         my ($cx, $cy) = $object->ScreenToClient($sx, $sy);
>
>         # See if we're in the client area ...
>         my ($cl, $ct, $cr, $cb) = $object->GetClientRect();
>
>         if (    $cx < $cl or $cx > $cr
>              or $cy < $ct or $cy > $cb ) {
>                 # not in client area, pass to defwindowproc
>                 return 1;
>         }
>
>         # In client area, return HTCAPTION
>         $object->Result(HTCAPTION);
>         return 0;
> }
> __END__
>
> Regards,
> Rob.
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads, discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> Perl-Win32-GUI-Users mailing list
> Perl-Win32-GUI-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
> http://perl-win32-gui.sourceforge.net/
>

Yehh it's works fine. Thanks you both!

Reply via email to