unit antpri;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TFormaAnteriorPrincipal = class(TForm)
    Panel1: TPanel;
    Bevel2: TBevel;
    Bevel3: TBevel;
    Bevel4: TBevel;
    Label2: TLabel;
    Panel2: TPanel;
    Shape1: TShape;
    Label1: TLabel;
    procedure Panel2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Panel1Click(Sender: TObject);
    procedure Shape1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormPaint(Sender: TObject);
    procedure Label2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    procedure VentanaMueve(var M: TWMNCHitTest);
  end;

var
  FormaAnteriorPrincipal: TFormaAnteriorPrincipal;

implementation

uses Principa;

{$R *.DFM}

{****datos de la ventana*****}

procedure actualizacoordenadas;
begin

with FormaPrincipal do
begin
FormaPrincipal.Top:=FormaAnteriorPrincipal.Top+23;
FormaPrincipal.Left:=FormaAnteriorPrincipal.Left+3;
FormaPrincipal.Width:=FormaAnteriorPrincipal.Width-6;
FormaPrincipal.Height:=FormaAnteriorPrincipal.Height-Panel1.Height+10;
end;

end;


procedure ponecoordenadas;
begin
with FormaPrincipal do
begin
FormaPrincipal.Top:=FormaAnteriorPrincipal.Top+23;
FormaPrincipal.Left:=FormaAnteriorPrincipal.Left+3;
end;
end;

procedure TFormaAnteriorPrincipal.VentanaMueve(var M: TWMNCHitTest);
 var P: TPoint;
begin
 inherited;
 GetCursorPos(P);
 P.X := P.X - Left;
 P.Y := P.Y - Top;
 with Panel1 do
  if (P.X > Left) and (P.X < (Left + Width)) and (P.Y > Top) and (P.Y < (Top + Height)) then
   M.Result := htCaption;
end;

procedure poneforma;
begin
with FormaAnteriorPrincipal do
begin
Tag:=1;
FormaPrincipal.Show;
FormaPrincipal.Visible:=True;
ponecoordenadas;
end;
end;

{******************************}

{*****procedimientos nativos*******}

procedure TFormaAnteriorPrincipal.Panel2Click(Sender: TObject);
begin
{******panel que simula el boton cerrar*****}
Tag:=1;
FormaPrincipal.Close;
Close;
{************************************}
end;

procedure TFormaAnteriorPrincipal.FormActivate(Sender: TObject);
begin
{***cuando se activa la forma de atras***}
if Tag=0 then
begin
actualizacoordenadas;
{FormaPrincipal.Show;}
poneforma;
end;
Tag:=1;
{*********************}
end;

procedure TFormaAnteriorPrincipal.Panel1Click(Sender: TObject);
begin
{***cuando se da click vuelve a mostrar**}
poneforma;
end;

procedure TFormaAnteriorPrincipal.Shape1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
{******click en el shape cuadro*****}
poneforma;
end;

procedure TFormaAnteriorPrincipal.Panel1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
{****** event on mouse down panel que mueve la forma***}
FormaPrincipal.Visible:=False;
ReleaseCapture;
SendMessage(FormaAnteriorPrincipal.Handle, WM_SYSCOMMAND, $F012, 0);
poneforma;
{**********}
end;

procedure TFormaAnteriorPrincipal.FormPaint(Sender: TObject);
begin

{*****cierra la forma al regresar de cerrado******}
if FormaPrincipal.BotonSalir.Tag=1000 then
begin
Close;
FormaPrincipal.BotonSalir.Tag:=0;
{****************}

end;

end;

procedure TFormaAnteriorPrincipal.Label2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FormaPrincipal.Visible:=False;
ReleaseCapture;
SendMessage(FormaAnteriorPrincipal.Handle, WM_SYSCOMMAND, $F012, 0);
poneforma;
end;

end.
