Page 1 of 3

ON MOUSEDRAG ?

Posted: Tue Sep 10, 2013 2:07 am
by andyglezl
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?
-------------------------------------------------------------------------

ON MOUSEDRAG ?

Posted: Tue Sep 10, 2013 11:51 am
by Pablo César
Hola Andrés,

Fijate si este ejemplo te ayuda a resolver. Try this:
MoveWindow2.rar
(825.17 KiB) Downloaded 410 times
Message re-edited to attached mouse pointers files and for second time to include source code file (was missing, sorry).

ON MOUSEDRAG ?

Posted: Tue Sep 10, 2013 12:05 pm
by Pablo César
Disculpame. La solucion que presenté, creo que no resuelve tu caso.

Sorry. This example which I had presented, will not solve your case.

Re: ON MOUSEDRAG ?

Posted: Tue Sep 10, 2013 2:28 pm
by esgici
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 3544 times
MoveWindow.zip
Source ( .prg, fmg, hbp, .bmp ) files of Moving Window sample
(5.94 KiB) Downloaded 161 times
Happy HMG'ing :D

Re: ON MOUSEDRAG ?

Posted: Tue Sep 10, 2013 2:34 pm
by bpd2000
Thank you, Esgici for sharing

Re: ON MOUSEDRAG ?

Posted: Tue Sep 10, 2013 2:59 pm
by srvet_claudio
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

Re: ON MOUSEDRAG ?

Posted: Tue Sep 10, 2013 4:02 pm
by esgici
srvet_claudio wrote: ...
See this code:
...
Apparently, we need ON MOVE event ;)

Viva HMG :D

ON MOUSEDRAG ?

Posted: Tue Sep 10, 2013 4:19 pm
by Pablo César
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 !

ON MOUSEDRAG ?

Posted: Tue Sep 10, 2013 8:12 pm
by Pablo César
Hereunder is some cursor pointers, one is animated cursor pointer. :)
New_Mouse_pointers.rar
(2.7 KiB) Downloaded 253 times
I hope you enjoy ! (Sorry I couldn't resist it...)

Re: ON MOUSEDRAG ?

Posted: Tue Sep 10, 2013 9:28 pm
by andyglezl
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