Prevent a window can be moved

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

jparada
Posts: 220
Joined: Fri Jan 23, 2009 5:18 pm

Prevent a window can be moved

Post by jparada » Sun Mar 28, 2010 8:16 am

Hi,

Is there any way (or trick) to prevent a user can not move a window by clicking on the title bar of the window (I hope I've explained).

Please I await your comments.

Best Regards
Javier

User avatar
esgici
Posts: 4245
Joined: Wed Jul 30, 2008 9:17 pm
Location: iskenderun / Turkiye
Has thanked: 128 times
Been thanked: 40 times
Contact:

Re: Prevent a window can be moved

Post by esgici » Sun Mar 28, 2010 8:53 am

jparada wrote: Is there any way (or trick) to prevent a user can not move a window by clicking on the title bar of the window
Hola Javier

AFAIK we haven't a NOMOVE keyword in DEFINE WINDOW statement. IMHO only you can use NOCAPTION for prevent user to use the title bar (if appropriate your need).

Saludos, Regards

--

Esgici
Viva INTERNATIONAL HMG :D

User avatar
Czarny_Pijar
Posts: 172
Joined: Thu Mar 18, 2010 11:31 pm
Location: 19.2341 E 50.2267 N

Re: Prevent a window can be moved

Post by Czarny_Pijar » Sun Mar 28, 2010 2:06 pm

jparada
For my own curiosity I've checked every available option in the HMG. Looks like at this time with this tool you can't do this.

User avatar
mol
Posts: 2602
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 50 times
Been thanked: 22 times
Contact:

Re: Prevent a window can be moved

Post by mol » Sun Mar 28, 2010 2:12 pm

You can prevent moving the window in this way:
1. Rememeber the position of window
2. When user moves window - move it programmatically to the previous position

User avatar
Rathinagiri
Posts: 4992
Joined: Tue Jul 29, 2008 6:30 pm
Location: Sivakasi, India
Has thanked: 64 times
Been thanked: 78 times
Contact:

Re: Prevent a window can be moved

Post by Rathinagiri » Sun Mar 28, 2010 2:20 pm

You are gr8 Marek. :)

A creative and logical approach to the problem.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.


jparada
Posts: 220
Joined: Fri Jan 23, 2009 5:18 pm

Re: Prevent a window can be moved

Post by jparada » Sun Mar 28, 2010 4:16 pm

Hi,

Thanks for your answers.

Esgici:
AFAIK we haven't a NOMOVE keyword in DEFINE WINDOW statement. IMHO only you can use NOCAPTION for prevent user to use the title bar (if appropriate your need).
The problem is I need the title bar.

Czarny_Pijar
For my own curiosity I've checked every available option in the HMG. Looks like at this time with this tool you can't do this.
I already knew

Marek
You can prevent moving the window in this way:
1. Rememeber the position of window
2. When user moves window - move it programmatically to the previous position
Sorry, I personally do not like this "trick"

Thanks

Best Regards
Javier

User avatar
esgici
Posts: 4245
Joined: Wed Jul 30, 2008 9:17 pm
Location: iskenderun / Turkiye
Has thanked: 128 times
Been thanked: 40 times
Contact:

Re: Prevent a window can be moved

Post by esgici » Sun Mar 28, 2010 10:20 pm

jparada wrote:
Marek wrote:You can prevent moving the window in this way:
1. Rememeber the position of window
2. When user moves window - move it programmatically to the previous position
Sorry, I personally do not like this "trick"
Hola Javier

In my opinion, the suggestion of Marek is cool. Though you don't like, take a look at this :

Code: Select all

#include "minigui.ch"

FUNC Main()

   nWindWidth  := 500
   nWindHeight := 400
   
   nUnMWinCol := ( GetDesktopWidth() - nWindWidth ) / 2
   nUnMWinRow := ( GetDesktopHeight() - nWindHeight ) / 2
   
   DEFINE WINDOW frmUnMoveable ;
      AT 0,0 ;
      WIDTH 500 ;
      HEIGHT 400 ;
      TITle "Unmoveable Window" ;
      MAIN 
                                              
      ON KEY ESCAPE ACTION frmUnMoveable.Release      
      
      DEFINE TIMER Timer_1 ;
                 INTERVAL 100 ;
                 ACTION { || thisWindow.Row := nUnMWinRow, thisWindow.Col := nUnMWinCol }
      
   END WINDOW

   frmUnMoveable.CENTER

   ACTIVATE WINDOW frmUnMoveable 

RETU 
Hopefully, a friend may achieve this by a less "tricky" way ;)

Saludos / Regards

--

Esgici
Viva INTERNATIONAL HMG :D

User avatar
srvet_claudio
Posts: 1832
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 24 times
Been thanked: 54 times
Contact:

Re: Prevent a window can be moved

Post by srvet_claudio » Sun Mar 28, 2010 10:46 pm

Hi friend Esgici,
very nice your code ;)

I would add

Code: Select all

ON MAXIMIZE (thisWindow.restore)


best regards,
Claudio Soto
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
srvet_claudio
Posts: 1832
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 24 times
Been thanked: 54 times
Contact:

Re: Prevent a window can be moved

Post by srvet_claudio » Sun Mar 28, 2010 11:13 pm

Hola a todos,
les dejo un par de funciones generales para bloquear el movimiento de una determinada ventana, para un mejor funcionamiento seria preferible para no interferir con el botón de maximizar que la misma fuese difinida como NOMAXIMIZE o en su defecto con
ON MAXIMIZE (thisWindow.Restore), de lo contrario cuando pulsan el botón de maximizar la ventana permanece con el mismo tamaño
pero el sistema toma como que se maximizo y cambia dicho botón a RESTORE, y viceversa.
Pueden comprobarlo en el ejemplo que les dejo abajo.
Saludos,
Claudio Soto.


***************************************************************************************************
* SINTAXIS:
*
* MOVE_WINDOW_F (<cWindowName>) // BLOQUEA movimiento de la ventana
* MOVE_WINDOW_T (<cWindowName>) // DESBLOQUEA movimiento de la ventana
* MOVE_WINDOW (<cWindowName>) // Retorna .T. MOVIBLE --- Retorna .F. NOMOVIBLE
*
***************************************************************************************************

Code: Select all

****************************************************************************
* PROGRAMA: NO MOVE WINDOW
* LENGUAJE: HARBOUR-MINIGUI 3.0.26
* FECHA:    28 MARZO 2010
* AUTOR:    CLAUDIO SOTO
* PAIS:     URUGUAY
* E-MAIL:   srvet@adinet.com.uy
****************************************************************************


***************************************************************************************************
* SINTAXIS:
*
* MOVE_WINDOW_F (<cWindowName>)   // BLOQUEA movimiento de la ventana
* MOVE_WINDOW_T (<cWindowName>)   // DESBLOQUEA movimiento de la ventana
* MOVE_WINDOW   (<cWindowName>)   // Retorna .T. MOVIBLE --- Retorna .F. NOMOVIBLE 
* 
*******************************************************************************************************


****************************************************************************************************
* DEFINICION DE LOS COMANDOS
****************************************************************************************************

#xtranslate MOVE_WINDOW_FALSE (<cWindowName>);
     =>;
     MOVE_WINDOW_F (<cWindowName>)
     
#xtranslate MOVE_WINDOW_TRUE (<cWindowName>);
     =>;
     MOVE_WINDOW_T (<cWindowName>)
     
//     MOVE_WINDOW (<cWindowName>)


#include "minigui.ch"
declare window form_2

Function Main

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 400 ;
		HEIGHT 500 ;
		TITLE 'NO MOVE WINDOW' ;
		MAIN  //ON MAXIMIZE (thisWindow.Restore) 
		
        @ 10,10 LABEL Label_1 VALUE IF (MOVE_WINDOW ("Form_1"),"MOVER SI","MOVER NO") 
       		
        @ 100, 100 BUTTON boton_1 CAPTION "NO MOVER" ACTION {|| MOVE_WINDOW_FALSE ("Form_1"), Form_1.Label_1.Value := IF (MOVE_WINDOW ("Form_1"),"MOVER SI","MOVER NO")} 
        @ 100, 250 BUTTON boton_2 CAPTION "MOVER"    ACTION {|| MOVE_WINDOW_TRUE  ("Form_1"), Form_1.Label_1.Value := IF (MOVE_WINDOW ("Form_1"),"MOVER SI","MOVER NO")} 
		
        @ 200, 100 BUTTON boton_3 CAPTION "Ventana 2" ACTION ventana2 (1)
        @ 200, 250 BUTTON boton_4 CAPTION "NO MOVER 2" ACTION ventana2 (2)
		
	END WINDOW

	
	Form_1.Center 
		
	Form_1.Activate 

Return

*****************************************************************************************************
Procedure Ventana2 (n)

IF n = 1 
    IF IsWindowDefined (form_2)
       RETURN
    ENDIF
     
    DEFINE WINDOW Form_2 ;
		AT 10,10 ;
		WIDTH 300 ;
		HEIGHT 300 ;
		TITLE 'Vent2' ;
		CHILD     
		
	END WINDOW
    Form_2.Activate
ENDIF

IF n = 2 .AND. IsWindowDefined (form_2)   
   MOVE_WINDOW_FALSE ("Form_2")
ENDIF   
Return

******************************************************************************************************
****************************************************************************************************
* DEFINICION DE LAS FUNCIONES
****************************************************************************************************



Procedure MOVE_WINDOW_F (vent)
Local y := GetProperty (vent , "ROW") 
Local x := GetProperty (vent , "COL")
Local h := GetProperty (vent , "HEIGHT") 
Local w := GetProperty (vent , "WIDTH")    
    
Local ctrl := "tmr_"+vent
     
   IF .NOT. (IsControlDefined (&ctrl , &vent))
       DEFINE TIMER &ctrl OF &vent INTERVAL 50 ACTION NO_MOV_WIN_C (GetFormHandle(vent), y, x, h, w)    
   ENDIF
   
Return

********************************************************************************************************
Procedure MOVE_WINDOW_T (vent)
Local ctrl := "tmr_"+vent
   
   IF  IsControlDefined (&ctrl , &vent)
       DoMethod (vent ,ctrl ,"Release")
   ENDIF
   
Return


*********************************************************************************************************************
Function MOVE_WINDOW (vent)
Local ctrl := "tmr_"+vent
   
Return .NOT.(IsControlDefined (&ctrl , &vent))





*#########################################################################################################################
*   FUNCION EN C        
*#########################################################################################################################

#pragma begindump

#include <shlobj.h>   
#include <winuser.h>
#include <windows.h>

#include "hbapi.h"



//**********************************************************************************
// NO_MOV_WIN_C (hWND, y, x, h, w)
//**********************************************************************************
HB_FUNC (NO_MOV_WIN_C)
{  
   HWND hWND;
   int x, y, h, w;
   
   hWND = (HWND) hb_parnl (1);
   y    =  hb_parni (2);
   x    =  hb_parni (3);  
   h    =  hb_parni (4);
   w    =  hb_parni (5);
   
   SetWindowPos (hWND, HWND_TOP, x, y, w, h, SWP_NOZORDER | SWP_NOACTIVATE);
} 
 
#pragma enddump

Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

Post Reply

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests