ON MOUSEDRAG ?

Moderator: Rathinagiri

User avatar
andyglezl
Posts: 859
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 7 times
Been thanked: 25 times
Contact:

ON MOUSEDRAG ?

Post by andyglezl » Tue Sep 10, 2013 2:07 am

Hola a todos

Como puedo saber cuando se mueve de lugar una ventana ?
Probé con "ON MOUSEDRAG" pero no ejecuta mi funcion. Algun ejemplo ?
------------------------------------------------------------------------
Hello everyone

As I can know when moving from place a window?
I tried "ON MOUSEDRAG" but does not execute my function. Some example?
-------------------------------------------------------------------------
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Tue Sep 10, 2013 11:51 am

Hola Andrés,

Fijate si este ejemplo te ayuda a resolver. Try this:
MoveWindow2.rar
(825.17 KiB) Downloaded 310 times
Message re-edited to attached mouse pointers files and for second time to include source code file (was missing, sorry).
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Tue Sep 10, 2013 12:05 pm

Disculpame. La solucion que presenté, creo que no resuelve tu caso.

Sorry. This example which I had presented, will not solve your case.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
esgici
Posts: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 247 times
Been thanked: 91 times
Contact:

Post by esgici » Tue Sep 10, 2013 2:28 pm

andyglezl wrote: As I can know when moving from place a window?
I tried "ON MOUSEDRAG" but does not execute my function. Some example?
I'm not sure that I have understood correct :?

I hope attached sample will help you :arrow:
MovingWindow.JPG
Screenshoot of Moving Window sample
MovingWindow.JPG (20.88 KiB) Viewed 1325 times
MoveWindow.zip
Source ( .prg, fmg, hbp, .bmp ) files of Moving Window sample
(5.94 KiB) Downloaded 77 times
Happy HMG'ing :D
Viva INTERNATIONAL HMG :D

User avatar
bpd2000
Posts: 963
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 136 times
Been thanked: 43 times

Post by bpd2000 » Tue Sep 10, 2013 2:34 pm

Thank you, Esgici for sharing
BPD
Convert Dream into Reality through HMG

User avatar
srvet_claudio
Posts: 1958
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 32 times
Been thanked: 125 times
Contact:

Post by srvet_claudio » Tue Sep 10, 2013 2:59 pm

andyglezl wrote:Hola a todos

Como puedo saber cuando se mueve de lugar una ventana ?
Probé con "ON MOUSEDRAG" pero no ejecuta mi funcion. Algun ejemplo ?
------------------------------------------------------------------------
Hello everyone

As I can know when moving from place a window?
I tried "ON MOUSEDRAG" but does not execute my function. Some example?
-------------------------------------------------------------------------
See this code:

Code: Select all

#include "hmg.ch"

Function Main

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 ;
		HEIGHT 480 ;
		TITLE 'Move Window' ;
		MAIN 

      @  100 , 10 LABEL Label_X VALUE "" AUTOSIZE
      @  150 , 10 LABEL Label_Y VALUE "" AUTOSIZE
	END WINDOW
   
   CENTER WINDOW Form_1

   #define WM_MOVE 3
   CREATE EVENT PROCNAME MoveTest() HWND Form_1.HANDLE MSG WM_MOVE

	ACTIVATE WINDOW Form_1 

Return


FUNCTION MoveTest()
LOCAL xPos := LOWORD(EventlParam())
LOCAL yPos := HIWORD(EventlParam())
   Form_1.Label_X.Value := "X = " + HB_NTOS(xPos)
   Form_1.Label_Y.Value := "Y = " + HB_NTOS(yPos)
RETURN NIL
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
esgici
Posts: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 247 times
Been thanked: 91 times
Contact:

Post by esgici » Tue Sep 10, 2013 4:02 pm

srvet_claudio wrote: ...
See this code:
...
Apparently, we need ON MOVE event ;)

Viva HMG :D
Viva INTERNATIONAL HMG :D

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Tue Sep 10, 2013 4:19 pm

srvet_claudio wrote:See this code:
..//..
#define WM_MOVE 3
CREATE EVENT PROCNAME MoveTest() HWND Form_1.HANDLE MSG WM_MOVE
..//..
FUNCTION MoveTest()
LOCAL xPos := LOWORD(EventlParam())
LOCAL yPos := HIWORD(EventlParam())
Form_1.Label_X.Value := "X = " + HB_NTOS(xPos)
Form_1.Label_Y.Value := "Y = " + HB_NTOS(yPos)
RETURN NIL
Very Good Doctor !!

So the code I posted could be improved like this:

Code: Select all

#include "hmg.ch"
#define HTCAPTION          2
#define WM_MOVE            3
#define WM_NCLBUTTONDOWN   161

Function Main
DEFINE WINDOW Form_1 ;
	AT 0,0 ;
	WIDTH 400 ;
	HEIGHT 200 ;
	TITLE 'Hello World!' ;
	MAIN ;
	ON MOUSECLICK MoveActiveWindow()
	
	ON KEY ESCAPE ACTION ThisWindow.Release
    
	DEFINE STATUSBAR
        STATUSITEM "Click on Form and holding mouse's button for moving this window"
    END STATUSBAR
		
	DEFINE LABEL Label_1
		ROW	100
		COL	10
		VALUE ""
	END LABEL

END WINDOW
// Form_1.Cursor := "hand32-32.cur"
Form_1.Cursor := "Move-32.cur"
CENTER WINDOW Form_1
CREATE EVENT PROCNAME MoveTest() HWND Form_1.HANDLE MSG WM_MOVE
ACTIVATE WINDOW Form_1
Return Nil

Function MoveActiveWindow( hWnd )
DEFAULT hWnd := GetActiveWindow()

PostMessage( hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0 )
// FileCursor( "Grabbed32-32.cur" )
FileCursor( "Maggy.ani" )
Return Nil

Function MoveTest()
Local xPos := LOWORD(EventlParam())
Local yPos := HIWORD(EventlParam())

Form_1.Label_1.Value:="Lin: "+Str(yPos,3,0)+" / Col: "+Str(xPos,3,0)   
Return Nil

#pragma BEGINDUMP

#include <windows.h>

HB_FUNC( FILECURSOR )
{
   hb_retnl( ( LONG ) SetCursor( LoadCursorFromFile( hb_parc( 1 ) ) ) );
}

#pragma ENDDUMP
Nice example for move events. Thanks again Claudio !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Tue Sep 10, 2013 8:12 pm

Hereunder is some cursor pointers, one is animated cursor pointer. :)
New_Mouse_pointers.rar
(2.7 KiB) Downloaded 174 times
I hope you enjoy ! (Sorry I couldn't resist it...)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
andyglezl
Posts: 859
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 7 times
Been thanked: 25 times
Contact:

Post by andyglezl » Tue Sep 10, 2013 9:28 pm

Gracias Pablo César, esgici y Claudio

Revisé los ejemplos que enviaron e hice esto.

La idea que traigo es crear 2 ventanas, y que al mover la ventana 'Main',
la ventana 'Child' se acople a un lado de la 'Main'.

El siguiente código ya lo hace, hay que mover la ventana MAIN y darle click,
la ventana CHILD se ubicara a un lado de la MAIN. Lo que quiero es que
automaticamente la ventana CHILD se "acople" al deja de pulsar el botón del
ratón.
-------------------------------------------------------------------------
Thanks Pablo Cesar, Esgici and Claudio

I checked the examples sent and made this.

The idea is to create 2 windows bring, and that moving the window 'Main'
window 'Child' engages a side of the 'Main'.

The following code already does, you have to move the MAIN window and give click,
CHILD window was located on one side of the MAIN. What I want is that
CHILD window is automatically "attach" to stop pressing the button
mouse.
-----------------------------------------------------------------------------

Code: Select all

#include "hmg.ch"
#define HTCAPTION          2
#define WM_MOVE            3
#define WM_NCLBUTTONDOWN   161

Function Main
    DEFINE WINDOW Form_1 AT 0,0 WIDTH 400 HEIGHT 600 TITLE 'Hello World!' MAIN ;
		   ON MOUSECLICK MoveActiveWindow() ;
		   ON INIT (  CreaChild( GetFormHandle('Form_1') ), MoveActiveWindow( hWnd )  )
       
		ON KEY ESCAPE ACTION ThisWindow.Release
		
		DEFINE STATUSBAR
			STATUSITEM "Click on Form and holding mouse's button for moving this window"
		END STATUSBAR
    END WINDOW
    
    CENTER WINDOW Form_1
    ACTIVATE WINDOW Form_1
Return Nil
FUNCTION CreaChild()
	Local xPos := Form_1.Row
	Local yPos := Form_1.Col
	Local nWidth := Form_1.Width
	
	DEFINE WINDOW Form_2 AT xPos,yPos+nWidth WIDTH 300 HEIGHT 200 TITLE 'WinChild' CHILD 
       
		ON KEY ESCAPE ACTION ThisWindow.Release
       
		DEFINE STATUSBAR
                STATUSITEM "This window CHILD will be 'anchored' to the MAIN ..."
		END STATUSBAR
    
    END WINDOW
    ACTIVATE WINDOW Form_2
RETURN Nil

Function MoveActiveWindow( hWnd )
	Local xPos := Form_1.Row
	Local yPos := Form_1.Col
	Local nWidth := Form_1.Width
	DEFAULT hWnd := GetActiveWindow()
	
	PostMessage( hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0 )
	Form_1.StatusBar.Item(1):="Lin: "+Str(yPos,3,0)+" / Col: "+Str(xPos,3,0)
	Form_2.Row:=xPos
	Form_2.Col:=yPos+nWidth
	
Return Nil
Attachments
WinAcople.png
WinAcople.png (388.85 KiB) Viewed 1256 times
Andrés González López
Desde Guadalajara, Jalisco. México.

Post Reply