ON MOUSEDRAG ?

Moderator: Rathinagiri

User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: ON MOUSEDRAG ?

Post by esgici »

andyglezl wrote:...
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.
Hola Andres

Good idea, nice implementation; thank to share;
wherever goes child, returns to home when his father call 8-)

Only two little thought :

- Although the line

PostMessage( hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0 )

commented, program work with no difference ( as far as I see ).

- When MAIN form clicked after CHILD closed, a problem occurs :

Error: HMG 3.1.5 (2013.07.31)
Window: Form_2 is not defined. Program terminated

Called from SETPROPERTY(7065)
Called from MOVEACTIVEWINDOW(46)
...

Anyway again, thank to share;

every sample grows up our knowledge :arrow:

Viva HMG :D
Viva INTERNATIONAL HMG :D
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: ON MOUSEDRAG ?

Post by andyglezl »

Como mencionó esgici, necesitamos el evento ON MOVE !

Añadí los eventos ON SIZE, ON MAXIMIZE, ON MINIMIZE y si
hace lo que yo esperaba.
-------------------------------------------------------------
As mentioned Esgici, we need the event ON MOVE !

I added events ON SIZE, ON MAXIMIZE, ON MINIMIZE and if
does what I expected.

--------------------------------------------------------------

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( GetFormHandle('Form_1') ) ;
		   ON INIT     ( CreaChild( GetFormHandle('Form_1') ), MoveActiveWindow( GetFormHandle('Form_1') ) )  ;
		   ON SIZE     MoveActiveWindow( GetFormHandle('Form_1') )   ;
		   ON MAXIMIZE MoveActiveWindow( GetFormHandle('Form_1') )   ;
		   ON MINIMIZE MoveActiveWindow( GetFormHandle('Form_1') )
       
		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.Col
	Local yPos := Form_1.Row
	Local nWidth := Form_1.Width
	
	DEFINE WINDOW Form_2 AT yPos,xPos+nWidth WIDTH 300 HEIGHT 200 TITLE 'WinChild' CHILD NOSYSMENU NOCAPTION
       
		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.Col
	Local yPos := Form_1.Row
	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:=yPos
	Form_2.Col:=xPos+nWidth
	
Return Nil
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: ON MOUSEDRAG ?

Post by andyglezl »

Tienes razón esgici

Simplificandolo un poco mas...
-------------------------------------------------------------------------------------

Code: Select all

#include "hmg.ch"

Function Main
    DEFINE WINDOW Form_1 AT 0,0 WIDTH 400 HEIGHT 600 TITLE 'Hello World!' MAIN ;
		   ON MOUSECLICK MoveActiveWindow( ) ;
		   ON INIT     ( CreaChild( )  )                ;
		   ON SIZE        MoveActiveWindow( )     ;
		   ON MAXIMIZE MoveActiveWindow( )    ;
		   ON MINIMIZE  MoveActiveWindow( )
       
		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.Col
	Local yPos := Form_1.Row
	Local nWidth := Form_1.Width
	
	DEFINE WINDOW Form_2 AT yPos,xPos+nWidth WIDTH 300 HEIGHT 200 TITLE 'WinChild' CHILD NOSYSMENU NOCAPTION
       
		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( )
	Local xPos := Form_1.Col
	Local yPos := Form_1.Row
	Local nWidth := Form_1.Width
	Form_1.StatusBar.Item(1):="Lin: "+Str(yPos,3,0)+" / Col: "+Str(xPos,3,0)
	Form_2.Row:=yPos
	Form_2.Col:=xPos+nWidth
Return Nil
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: ON MOUSEDRAG ?

Post by esgici »

andyglezl wrote: I added events ON SIZE, ON MAXIMIZE, ON MINIMIZE and if
does what I expected.
Good, thank :arrow:

Now, a bit changed :

wherever goes father, when he call child returns to home :arrow:
( because child can't go anywhere :( )

Viva HMG :D
Viva INTERNATIONAL HMG :D
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: ON MOUSEDRAG ?

Post by andyglezl »

Hola esgici
Revisando.... lo que comentas de:
---------------------------------
Hello Esgici
Reviewing .... what you mention:
---------------------------------
- Although the line

PostMessage( hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0 )

commented, program work with no difference ( as far as I see ).
---------------------------------------------------------------------------
Como estaba anteriormente, si tu "tomas" la ventana en cualquier parte
de ella, se puede "mover" a cualquier lado, no solamente de la parte de arriba.
( gracias Pablo César )
---------------------------------------------------------------------------
As was previously, if you "take" the window anywhere
of it, you can "move" anywhere, not only from the top.
(Thanks Pablo Cesar)
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: ON MOUSEDRAG ?

Post by esgici »

andyglezl wrote:...if you "take" the window anywhere
of it, you can "move" anywhere, not only from the top.
I had missed it :(

Happy HMG'ing :D
Last edited by esgici on Wed Sep 11, 2013 3:22 am, edited 1 time in total.
Viva INTERNATIONAL HMG :D
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

ON MOUSEDRAG ?

Post by Pablo César »

Andrés, tomé tu ejemplo, más lo que yo ya habia postado y más la idea imprecindible del Claudio, surgió este efecto:

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( GetFormHandle('Form_1') ) ;
     ON INIT CreaChild() ;
     ON SIZE (MoveTest(),ChgChild()) ;
     NOMAXIMIZE NOMINIMIZE
   
  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
CREATE EVENT PROCNAME MoveTest() HWND Form_1.HANDLE MSG WM_MOVE
ACTIVATE WINDOW Form_1
Return Nil

Function CreaChild()
Local xPos := Form_1.Col
Local yPos := Form_1.Row
Local nWidth := Form_1.Width

DEFINE WINDOW Form_2 AT yPos,xPos+nWidth WIDTH 300 HEIGHT 200 TITLE 'WinChild' CHILD NOSYSMENU 
    
   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 )
PostMessage( hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0 )
Return Nil

Function MoveTest()
Local xPos := LOWORD(EventlParam())
Local yPos := HIWORD(EventlParam())
Local nWidth := Form_1.Width

Form_1.StatusBar.Item(1):="Lin: "+Str(yPos,4,0)+" / Col: "+Str(xPos,4,0)+" | "+Str(nWidth,4,0)
ChgChild()
Return Nil

Function ChgChild()
Local xPos := Form_1.Col
Local yPos := Form_1.Row
Local nWidth := Form_1.Width

Form_2.Row:=yPos
Form_2.Col:=xPos+nWidth
Return Nil
Fijate si es o que querias.

I mixed up all examples, but the most important is to create the MOVE event that Claudio has indicated.
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

ON MOUSEDRAG ?

Post by Pablo César »

Code source of my previous message was re-edited for third time. Please check again Andrés
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: ON MOUSEDRAG ?

Post by andyglezl »

Gracias Pablo César

El detalle está en que yo todavia sigo con HMG 3.46 y algunas lineas me dan error.

CREATE EVENT PROCNAME MoveTest() HWND Form_1.HANDLE MSG WM_MOVE
Local xPos := LOWORD(EventlParam())
Local yPos := HIWORD(EventlParam())

Voy a ver si lo puedo solucionar. (espero pronto poder dar el paso a 3.1.5 )
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

ON MOUSEDRAG ?

Post by Pablo César »

andyglezl wrote:Voy a ver si lo puedo solucionar. (espero pronto poder dar el paso a 3.1.5 )
Creo que lo tienes que hacer cuanto antes. Es una pena no estar utilizando los beneficios de la nueva version.

--

IMO you need to uypdate sasp, It is a pity not using the benefits of the new version.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Post Reply