Bring your form close to the borders (like WinAmp)  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 25/12/99

Tip accessed 565 times

 


We will make it capturing and treating Windows TWMWINDOWPOSCHANGED message

  • Put this it lines to capture the message and to declare their treatment procedure in the private part of yours form declaration:


       private
         { Private declarations }
         procedure PegaAlBorde(var m: TWMWINDOWPOSCHANGED);
                             message WM_WINDOWPOSCHANGING ;
    



  • Now, put the procedure in the implementation part:


     procedure TForm1.PegaAlBorde(var m : TWMWINDOWPOSCHANGED);
     const
          {Sensibility}
          Sensibilidad:integer=4;
     var
        Dato:TRect;
     begin
         try
           {Aqui si el SystemPar... funciona,
                       porque estemos en Win95}
           SystemParametersInfo(SPI_GETWORKAREA,0,@Dato,0);
           if m.windowpos.x<=(Dato.Left+Sensibilidad)
             then m.windowpos.x:=Dato.Left;
           if m.windowpos.y<=(Dato.Top+Sensibilidad)
             then m.windowpos.y:=Dato.Top;
    
           if (m.windowpos.x+Width)>= (Dato.Right-Sensibilidad)
             then m.windowpos.x:=Dato.Right-Width;
           if (m.windowpos.y+Height)>= (Dato.Bottom-Sensibilidad)
             then m.windowpos.y:=Dato.Bottom-Height;
         except
           {Aqui si se trata de NT o algo en donde no tire Systempar...}
           {Here if is NT and Systempar... don't work...}
           if m.windowpos.x<=Sensibilidad then m.windowpos.x:=0;
           if m.windowpos.y<=Sensibilidad then m.windowpos.y:=0;
           if (m.windowpos.x+Width)>= (Screen.Width-Sensibilidad)
             then m.windowpos.x:=Screen.Width-Width;
           if (m.windowpos.y+Height)>= (Screen.Height-Sensibilidad)
             then m.windowpos.y:=Screen.Height-Height;
         end;
     end;