Page 1 of 2
Prevent a window can be moved
Posted: Sun Mar 28, 2010 8:16 am
by jparada
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
Re: Prevent a window can be moved
Posted: Sun Mar 28, 2010 8:53 am
by esgici
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
Re: Prevent a window can be moved
Posted: Sun Mar 28, 2010 2:06 pm
by Czarny_Pijar
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.
Re: Prevent a window can be moved
Posted: Sun Mar 28, 2010 2:12 pm
by mol
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
Re: Prevent a window can be moved
Posted: Sun Mar 28, 2010 2:20 pm
by Rathinagiri
You are gr8 Marek.
A creative and logical approach to the problem.
Re: Prevent a window can be moved
Posted: Sun Mar 28, 2010 2:22 pm
by mol
thx Rathi!
Re: Prevent a window can be moved
Posted: Sun Mar 28, 2010 4:16 pm
by jparada
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
Re: Prevent a window can be moved
Posted: Sun Mar 28, 2010 10:20 pm
by esgici
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
Re: Prevent a window can be moved
Posted: Sun Mar 28, 2010 10:46 pm
by srvet_claudio
Hi friend Esgici,
very nice your code
I would add
best regards,
Claudio Soto
Re: Prevent a window can be moved
Posted: Sun Mar 28, 2010 11:13 pm
by srvet_claudio
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