Alaska Software Inc. - Move an object
Username: Password:
AuthorTopic: Move an object
Thomas PoolMove an object
on Fri, 08 Apr 2016 12:56:49 +0200
Hi All,

Does somebody have a piece of example-code how to move 
(drag with mouse) an object on a drawing area and is willing to share it?

Thanks & regards, Thomas J. Pool
Raymond FischbachRe: Move an object
on Sat, 09 Apr 2016 16:19:49 +0200
Après mûre réflexion, Thomas Pool a écrit :
> Hi All,
>
> Does somebody have a piece of example-code how to move 
> (drag with mouse) an object on a drawing area and is willing to share it?
>
> Thanks & regards, Thomas J. Pool

Hi Thomas,

Maybe the Alaska sample c&n give you some hints?

Have a look in the folder "C:\...\SOURCE\samples\basics\DRAGDROP"

Best regards,
Raymond
Thomas BraunRe: Move an object
on Mon, 11 Apr 2016 08:35:43 +0200
Raymond Fischbach wrote:

 
> Maybe the Alaska sample c&n give you some hints?
> 
> Have a look in the folder "C:\...\SOURCE\samples\basics\DRAGDROP"

This won't help as it is about dragging items (e.g. files) from another
application (windows Explorer) to a Xbase++ application.

Thomas
Jim LeeRe: Move an object
on Mon, 11 Apr 2016 20:41:57 +0200
> Does somebody have a piece of example-code how to move
> (drag with mouse) an object on a drawing area and is willing to share it?

this Demo, using ot4xb, can move a SLE ( FROM XbpSLE ) but you can use other 
XbParts too.

* --------------------------------------- *
#include "ot4xb.ch"
#include "Appevent.ch"

#include "common.ch"
#include "xbp.ch"
#include "gra.ch"
 ---------------------------------------------------------------------------
#define WM_NCHITTEST        0x0084
#define WM_MOVING           0x0216
#define WM_DESTROY          0x0002
 ---------------------------------------------------------------------------
proc main()
local nEvent,oSle,oSle2,mp1 := NIL,mp2 := NIL, oXbp := NIL

   SETCOLOR( "N/W" )
   CLS
   ?? "Try to Drag & drop the GET"
   oSle:= DragableGet():new()
   oSle:tabStop := .T.
   oSle:create( , , {230,192}, {140,24} )

   oSle2:= DragableGet():new()
   oSle2:tabStop := .T.
   oSle2:create( , , {230,292}, {140,24} )

   SetAppfocus( oSle )

   nEvent := 0
   while nEvent != xbeP_Close
      nEvent := AppEvent( @mp1, @mp2, @oXbp )
      oXbp:HandleEvent( nEvent, mp1, mp2 )
   end
return
 ---------------------------------------------------------------------------
CLASS DragableGet FROM XbpSLE
 Sample other XbParts
*CLASS DragableGet FROM XbpStatic
*CLASS DragableGet FROM XbpPushButton
EXPORTED:
        --------------------------------------------------------------------
INLINE METHOD WndProc(hWnd,nMsg,wp,lp)
       if( nMsg == WM_NCHITTEST )
          @user32:SetFocus(hWnd)
          return 2
       elseif( nMsg == WM_MOVING )
          ::Moving( lp )
          return 1
       end
       return NIL
        --------------------------------------------------------------------
INLINE METHOD Create( oParent, oOwner, aPos, aSize, aPP, lVisible )

      ::xbpSLE:create( oParent, oOwner, aPos, aSize, aPP, lVisible )

 Sample other XbParts
*      ::xbpStatic:type := XBPSTATIC_TYPE_GROUPBOX
*      ::xbpStatic:create( oParent, oOwner, aPos, aSize, aPP, lVisible )
 Sample other XbParts
*      ::XbpPushButton:create( oParent, oOwner, aPos, aSize, aPP, lVisible )

       ot4xb_SubclassWindow( ::GetHWnd() , Self , WM_DESTROY)
       return Self
        --------------------------------------------------------------------
INLINE METHOD Moving(pRect)
       local aRect := iif( Empty(pRect) , NIL , PeekDWord(pRect,0,4) )
       if( aRect != NIL )
          @user32:MapWindowPoints(0, ::SetParent():GetHWND() , @aRect , 2)
          DispOutAt(0,35, "L:" + StrZero(aRect[1],5) +;
                        ", T:" + StrZero(aRect[2],5) +;
                        ", R:" + StrZero(aRect[3],5) +;
                        ", B:" + StrZero(aRect[4],5) )
       end
       return NIL
        --------------------------------------------------------------------
ENDCLASS
 ---------------------------------------------------------------------------

* --------------------------------------- *
Thomas PoolRe: Move an object
on Tue, 19 Apr 2016 14:01:33 +0200
Hi Jim,

Thanks for the code, mouse-dragging works fine!
Do you think it's possible to add arrow-cursor-moving to be able to move an
object in micro-steps?

Thanks & regards, Thomas 


Op Mon, 11 Apr 2016 20:41:57 +0200 schreef Jim Lee:

>> Does somebody have a piece of example-code how to move
>> (drag with mouse) an object on a drawing area and is willing to share it?
> 
> this Demo, using ot4xb, can move a SLE ( FROM XbpSLE ) but you can use other 
> XbParts too.
> 
> * --------------------------------------- *
> #include "ot4xb.ch"
> #include "Appevent.ch"
> 
> #include "common.ch"
> #include "xbp.ch"
> #include "gra.ch"
>  ---------------------------------------------------------------------------
> #define WM_NCHITTEST        0x0084
> #define WM_MOVING           0x0216
> #define WM_DESTROY          0x0002
>  ---------------------------------------------------------------------------
> proc main()
> local nEvent,oSle,oSle2,mp1 := NIL,mp2 := NIL, oXbp := NIL
> 
>    SETCOLOR( "N/W" )
>    CLS
>    ?? "Try to Drag & drop the GET"
>    oSle:= DragableGet():new()
>    oSle:tabStop := .T.
>    oSle:create( , , {230,192}, {140,24} )
> 
>    oSle2:= DragableGet():new()
>    oSle2:tabStop := .T.
>    oSle2:create( , , {230,292}, {140,24} )
> 
>    SetAppfocus( oSle )
> 
>    nEvent := 0
>    while nEvent != xbeP_Close
>       nEvent := AppEvent( @mp1, @mp2, @oXbp )
>       oXbp:HandleEvent( nEvent, mp1, mp2 )
>    end
> return
>  ---------------------------------------------------------------------------
> CLASS DragableGet FROM XbpSLE
>  Sample other XbParts
> *CLASS DragableGet FROM XbpStatic
> *CLASS DragableGet FROM XbpPushButton
> EXPORTED:
>         --------------------------------------------------------------------
> INLINE METHOD WndProc(hWnd,nMsg,wp,lp)
>        if( nMsg == WM_NCHITTEST )
>           @user32:SetFocus(hWnd)
>           return 2
>        elseif( nMsg == WM_MOVING )
>           ::Moving( lp )
>           return 1
>        end
>        return NIL
>         --------------------------------------------------------------------
> INLINE METHOD Create( oParent, oOwner, aPos, aSize, aPP, lVisible )
> 
>       ::xbpSLE:create( oParent, oOwner, aPos, aSize, aPP, lVisible )
> 
>  Sample other XbParts
> *      ::xbpStatic:type := XBPSTATIC_TYPE_GROUPBOX
> *      ::xbpStatic:create( oParent, oOwner, aPos, aSize, aPP, lVisible )
>  Sample other XbParts
> *      ::XbpPushButton:create( oParent, oOwner, aPos, aSize, aPP, lVisible )
> 
>        ot4xb_SubclassWindow( ::GetHWnd() , Self , WM_DESTROY)
>        return Self
>         --------------------------------------------------------------------
> INLINE METHOD Moving(pRect)
>        local aRect := iif( Empty(pRect) , NIL , PeekDWord(pRect,0,4) )
>        if( aRect != NIL )
>           @user32:MapWindowPoints(0, ::SetParent():GetHWND() , @aRect , 2)
>           DispOutAt(0,35, "L:" + StrZero(aRect[1],5) +;
>                         ", T:" + StrZero(aRect[2],5) +;
>                         ", R:" + StrZero(aRect[3],5) +;
>                         ", B:" + StrZero(aRect[4],5) )
>        end
>        return NIL
>         --------------------------------------------------------------------
> ENDCLASS
>  ---------------------------------------------------------------------------
> 
> * --------------------------------------- *
Jim LeeRe: Move an object
on Wed, 20 Apr 2016 00:23:23 +0200
> Thanks for the code, mouse-dragging works fine!
> Do you think it's possible to add arrow-cursor-moving to be able to move 
> an
> object in micro-steps?

using ot4xb_SubclassWindow() you are able to receive all Windows Message 
like

#define WM_KEYDOWN 0x0100
#define WM_KEYUP 0x0101

for more ask Pablo at www.xbwin.com