Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-03-2013
ricardopl65 ricardopl65 is offline
Miembro
 
Registrado: nov 2008
Posts: 25
Poder: 0
ricardopl65 Va por buen camino
perdona es esta la direccion
http://www.ricardoplaza.com/download/ventanatrans.avi
Responder Con Cita
  #2  
Antiguo 12-03-2013
Avatar de cesarsoftware
cesarsoftware cesarsoftware is offline
Miembro
 
Registrado: nov 2006
Posts: 241
Poder: 20
cesarsoftware Va por buen camino
¡Si! Eso es lo que busco.

Me das un poquito de info....porfa, anda... te invito a unas birras
Responder Con Cita
  #3  
Antiguo 12-03-2013
ricardopl65 ricardopl65 is offline
Miembro
 
Registrado: nov 2008
Posts: 25
Poder: 0
ricardopl65 Va por buen camino
me tendras que dar una habitación porque mi mujer me va a echar de casa
adjunto el proyecto tal como yo lo llevo hasta ahora.
Archivos Adjuntos
Tipo de Archivo: zip formtrans.zip (85,9 KB, 10 visitas)
Responder Con Cita
  #4  
Antiguo 12-03-2013
Avatar de cesarsoftware
cesarsoftware cesarsoftware is offline
Miembro
 
Registrado: nov 2006
Posts: 241
Poder: 20
cesarsoftware Va por buen camino
Me parece que vamos a tener que alquilar un apartamento entre los dos y tomarnos las birras en el bar del barrio, mi mujer tambien me quiere echar de casa, menos mal que nos quedan las niñas...y el portatil.

Bueno, visto, lo que has hecho es mover las ventanas hijas cuando mueves el padre con
Código Delphi [-]
procedure TFPrincipal.WMWindowPosChanging(var Message: TWMWindowPosChanging);
begin
  MoveFW();
  inherited;
end;
procedure TFPrincipal.MoveFW;
var
  X: Integer;
begin
  if Length(f2) > 0 then

    for X := 0 to Length(f2) - 1 do
    begin
      if (TForm2(f2[X]).Visible) then
      begin

        TForm2(f2[X]).moviendo := true;
        TForm2(f2[X]).Top := Self.Top + TForm2(f2[X]).difY;
        TForm2(f2[X]).Left := Self.Left + TForm2(f2[X]).difx;
        TForm2(f2[X]).moviendo := False;
      end;
    end;
end;

y en el hijo para apuntar la posicion actual
Código Delphi [-]
procedure tform2.WMWindowPosChanged(var Message: TWMWindowPosChanged);
begin
if moviendo=false then
begin
difx:=left-fprincipal.Left;
difY:=top-fprincipal.Top;
end;
inherited;
end;
para controlar los limites
Código Delphi [-]
procedure TForm2.WMMove(var Message: TWMMove);
begin
// Aqui habría que descontar la anchura de los bordes y el caption del form padre para mejorar el efecto.
   if leftthen left:=FPrincipal.Left;
   if (left+ width)>(fprincipal.Left+fprincipal.Width)  then
   left:=(fprincipal.Left+fprincipal.Width)-width;
   if (top + Height)>(fprincipal.top+fprincipal.Height)  then
   top:=(fprincipal.top+fprincipal.Height)-Height;

   if topthen top:=FPrincipal.Top;
end;

lo que me resulta curioso es el uso de esta funcion, le engañas a la cola de mensajes, quizas es que yo lo hubiera hecho con onmousemove,down y up, vamos la costumbre de cada uno, supongo
(editado: supongo que con un mensaje del sistema te ahorras asignar los eventos move,down,up a cada control, so burro)
Código Delphi [-]
procedure TForm2.WMNCHitTest(var Msg: TWMNCHitTest) ;
begin
inherited;
if Msg.Result = htClient then // Esta parte hace referencia a la parte donde se ha hecho click
Msg.Result := htCaption; // Aquí hace creer que donde se hizo click es el Caption Bar
end;

Desde luego el efecto es justo el deseado, me voy a poner a trabajar en esta tecnica que creo que va a ser la buena.

Cuando quieras las birras (o cafe)

PD: ¿porque se usa inherited, y cuando o porque se pone al principio o final de funciones? Thanks.

Última edición por cesarsoftware fecha: 12-03-2013 a las 19:13:24.
Responder Con Cita
  #5  
Antiguo 12-03-2013
ricardopl65 ricardopl65 is offline
Miembro
 
Registrado: nov 2008
Posts: 25
Poder: 0
ricardopl65 Va por buen camino
Tengo que aclar que parte del código ya estaba en esta web.
Responder Con Cita
  #6  
Antiguo 12-03-2013
ricardopl65 ricardopl65 is offline
Miembro
 
Registrado: nov 2008
Posts: 25
Poder: 0
ricardopl65 Va por buen camino
se pone inherited para invocar al metodo del ancestro del objeto en cuestión.
Por ejemplo en un metodo destroy primero liberas los objetos que hayas creado o cierras archivos etc y despues llamas a inherited para que continue con el proceso previsto. Si lo hicieses al reves cuando quisieras liberar tus objetos etc. ya se habria destruido el objeto.
En un Constructor create suele llamarse primero al inherited para que el objeto se cree normalmente y luego se añade la funcionalidad deseada. Si lo hicieses al reves, el metodo heredado sobreescribiria esa funcionalidad.
Es Importante el momento en el que se llama.
Responder Con Cita
  #7  
Antiguo 13-03-2013
Avatar de cesarsoftware
cesarsoftware cesarsoftware is offline
Miembro
 
Registrado: nov 2006
Posts: 241
Poder: 20
cesarsoftware Va por buen camino
Gracias por responder ricardo, suponia que ese era el efecto de inherited, pero confrmado queda claro.

Al final con el movimiento conjunto de ventanas el tema esta solucionado y un poco mas afinado
en este video se ve una muestra del efecto con topes incluidos
http://www.youtube.com/watch?v=yHiEy...ature=youtu.be

Hago un resumen de lo necesario, o lo que es lo mismo, la receta para cocinarlo

Formulario Padre o principal:

1 manejador de mensaje del movimiento de la pantalla principal
Código Delphi [-]
  private
    // Mover objetos DCx
    procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
3 variables publicas
Código Delphi [-]
  public
    // Posiciones relativas a la pantalla principal de los objetos DCx
    PxArriba: word;
    PxAbajo: word;
    PxDcha: word;
En el OnCreate (por ejemplo) calcular los margenes
en mi caso tengo abajo una TStatusBar
Código Delphi [-]
  PxArriba := GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYFRAME) - 1;
  PxAbajo := StatusBar.Height + GetSystemMetrics(SM_CYFRAME);
  PxDcha := GetSystemMetrics(SM_CXFRAME);

Al crear las ventanas hijas darle informacion sobre los limites para que no se pasen
Código Delphi [-]
  // Posiciones relativas a la pantalla principal
  DCx[i].PxArriba := FormRemoto.PxArriba;
  DCx[i].PxAbajo := FormRemoto.PxAbajo;
  DCx[i].PxDcha := FormRemoto.PxDcha;
  // posciones relativas respecto al padre (se guardan en una tabla)
  DCx[i].Left := StrToIntDef(SGmaquinas.Cells[4, i + 1], 1);
  DCx[i].Top := StrToIntDef(SGmaquinas.Cells[5, i + 1], 1);

El manejador que mueve las ventanas hijas cuando se mueve el padre
Código Delphi [-]
procedure TFormRemoto.WMWindowPosChanging(var Message: TWMWindowPosChanging);
var
  i, t: integer;
begin
  t := Length(DCx);
  if t = 0 then
    Exit;
  for i := 0 to t - 1 do
  begin
    if DCx[i] = nil then
      Continue;
    // DCx[i].Forma.Top es la nueva posicion de la ventana hija
    // DCx[i].Top es la posicion relativa de la ventana hija respento al padre, partiendo de 0,0
    DCx[i].Forma.Top := Self.Top + PxArriba + DCx[i].Top;
    DCx[i].Forma.Left := Self.Left + PxDcha + DCx[i].Left;
  end;
  inherited;
end;

Formulario hijo (semitrasparente con alphablendvalue)
unas variables publicas y los procedimientos de movimiento de raton
al final he deshechado los mensaje windows porque sale un movimiento "mas fino" de esta forma
Código Delphi [-]
  public // Variables de entrada publicas
    Forma: TForm;                 // Formulario contenedor
    FormularioPadre: TWinControl; // Parent
    PxArriba: word;               // SM_CYCAPTION + SM_CYMENU + SM_CYFRAME;
    PxAbajo: word;                // 19(StatuBar.Height) + SM_CYFRAME;
    PxDcha: word;                 // GetSystemMetrics(SM_CXFRAME);
    Left, Top: word;              // Posicion
    procedure LedOnMouseDown(Sender: TObject; Button: TMouseButton;
                             Shift: TShiftState; X, Y: Integer); // 1ª posicion
    procedure LedOnMouseMove(Sender: TObject; Shift: TShiftState;
                             X, Y: Integer); // mover panel
    procedure LedOnMouseUp(Sender: TObject; Button: TMouseButton;
                           Shift: TShiftState; X, Y: Integer); // nueva posicion

Crear los formularios hijos en tiempo de ejecucion
Código Delphi [-]
  Forma := TForm.CreateNew(FormularioPadre, 0); // CreateNew si no queremos usar un archivo .DFM
  Forma.Position := poDesigned;
  Forma.BorderStyle := bsNone;
  Forma.Left := FormularioPadre.Left + PxDcha + Left; // posicion relativa al inicio
  Forma.Top := FormularioPadre.Top + PxArriba + Top;
  if Icono = False then
  begin
    Forma.Width := 206;
    Forma.Height := 256;
  end
  else
  begin
    Forma.Width := 26;
    Forma.Height := 26;
  end;
  Forma.Color := clHotLight;
  Forma.Visible := Visible;
  Forma.AlphaBlend := True;
  Forma.AlphaBlendValue := 210;
  Forma.ShowHint := True;
  Forma.Hint := 'Left-Click y arrastre para mover';
  Forma.OnMouseDown := LedOnMouseDown;
  Forma.OnMouseMove := LedOnMouseMove;
  Forma.OnMouseUp := LedOnMouseUp;
...
crear los componentes vcl y asigarno a la forma y los evento si es necesario
  Lnumero := TLabel.Create(Forma);
  Lnumero.Parent := Forma;
  Lnumero.Top := LedOn.Top + 5;
  Lnumero.Left := LedOn.Left + 6;
  Lnumero.Height := 13;
  Lnumero.Width := 12;
  Lnumero.Transparent := True;
  Lnumero.Caption := IntToStr(Numero);
  Lnumero.ShowHint := True;
  Lnumero.Hint := LedOn.Hint;
  Lnumero.Visible := Icono;
  Lnumero.OnMouseDown := LedOnMouseDown;
  Lnumero.OnMouseMove := LedOnMouseMove;
  Lnumero.OnMouseUp := LedOnMouseUp;
...

y los manejadores de eventos
Código Delphi [-]
procedure TcapturadorDCx.LedOnMouseDown(Sender: TObject; Button: TMouseButton;
                                        Shift: TShiftState; X, Y: Integer);
begin
  // Capturar posicion inicial del ratón al comenzar a mover
  oldLeft := X;
  oldTop := Y;
  // Solo si es Shape LedOn
  if Sender is TForm then
    Exit;
  // Cambiar estado a icono o detalle
  if Button = mbRight then
  begin
    if Icono = True then
      SetIcono(False)
    else
      SetIcono(True);
    Exit;
  end;
  // comprobar si ha pulsado doble-click
  if ssDouble in Shift = False then
    Exit;
  // Encender o Apagar el capturador
  if DCx = nil then
    ActivaDCx // si no ha sido activado
  else
    if DCx.abierto = True then
      DesactivaDCx
    else
      if (DCx.conectando = False) and (Conectando = False) then
        ActivaDCx; // si las tarea DCx y el objeto TcapturadorDCx estan parados
end;

procedure TcapturadorDCx.LedOnMouseMove(Sender: TObject; Shift: TShiftState;
                                        X, Y: Integer);
var
  nX, nY: integer;
begin
  if ssLeft in Shift = False then
    Exit;
  // Controlar los limites
  // Izquierda
  if Forma.Left < (FormularioPadre.Left + PxDcha) then
  begin
    Forma.Left := FormularioPadre.Left + PxDcha;
    SetCursorPos(Forma.Left + X, Forma.Top + Y);
  end;
  // Derecha
  if (Forma.Left + Forma.Width) > (FormularioPadre.Left + FormularioPadre.Width - PxDcha) then
  begin
    Forma.Left := (FormularioPadre.Left + FormularioPadre.Width) - Forma.Width - PxDcha;
    SetCursorPos(Forma.Left + X, Forma.Top + Y);
  end;
  // Arriba
  if Forma.Top < (FormularioPadre.Top + PxArriba) then
  begin
    Forma.Top := FormularioPadre.Top + PxArriba;
    SetCursorPos(Forma.Left + X, Forma.Top + Y);
  end;
  // Abajo
  if (Forma.Top + Forma.Height) > (FormularioPadre.Top + FormularioPadre.Height - PxAbajo) then
  begin
    Forma.Top := (FormularioPadre.Top + FormularioPadre.Height) - Forma.Height - PxAbajo;
    SetCursorPos(Forma.Left + X, Forma.Top + Y);
  end;
  // Mover el objeto
  if X < oldLeft then
  begin
    nX := oldLeft - X;
    Forma.Left := Forma.Left - nX;
  end
  else
  begin
    nX := X - oldLeft;
    Forma.Left := Forma.Left + nX;
  end;
  if Y < oldTop then
  begin
    nY := oldTop - Y;
    Forma.Top := Forma.Top - nY;
  end
  else
  begin
    nY := Y - oldTop;
    Forma.Top := Forma.Top + nY;
  end;
end;

procedure TcapturadorDCx.LedOnMouseUp(Sender: TObject; Button: TMouseButton;
                                      Shift: TShiftState; X, Y: Integer);
begin
  Left := Forma.Left - (FormularioPadre.Left + PxDcha);
  Top := Forma.Top - (FormularioPadre.Top + PxArriba);
  Movido(Sender);
end;

procedure TcapturadorDCx.Movido(Sender: TObject);
begin
  // Sincronizar si tiene tarea asignada
  if Assigned(FOnMovido) then
    FOnMovido(Self);
end;

Ala, un pasito mas, gracias a todos.

Última edición por cesarsoftware fecha: 13-03-2013 a las 19:25:11.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Crear un form fsMDIForm y varios forms hijos citlalliDgp Varios 11 07-12-2007 15:13:31
¿Quien es mi Form Padre? gabrio OOP 4 16-10-2007 20:33:06
Nodo padre sin hijos en TTreeView jorgesl OOP 3 10-04-2006 20:24:11
Formulario padre con hijos oscarsanta Conexión con bases de datos 2 31-01-2006 13:17:13
como puedo poner form hijos ronimaxh Varios 5 22-10-2003 22:55:23


La franja horaria es GMT +2. Ahora son las 03:20:21.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi