Top

 Home |
Registrazione Login

 Navigazione : Categoria : GUI
   API ( 10 )
   Componenti ( 3 )
   Database - ADO ( 11 )
   Database - Altro ( 2 )
   Database - BDE ( 2 )
   Database - SQL ( 1 )
   GUI ( 12 )
   IDE ( 2 )
   Internet/Intranet ( 6 )
   Object Pascal ( 10 )
   Operazioni sui file ( 21 )
   Report ( 0 )
   Sistema ( 30 )
   VCL ( 14 )
 
 
       
Scheda

 

 

 Visto ( 852 )


Numero ID

 128

Oggetto

 Docking delle finestre Delphi ai bordi dello schermo

Inserito il

 18/02/2008

Scade il

 19/03/2008


 Nome  Giuseppe

Città

 ----
Cognome  ----

Via

 ----
 E-mail  Casella postale

Provincia

 ----

Tel...

 ----

Cap

 ----
 Difficolta'   7

Home

 ----
Foto  ----  

L'intento è di fare in modo che la nostra finestra si agganci automaticamente ai bordi dello schermo quando si trova a meno di una certa distanza (ad esempio 20 pixel) da essi.
Innanzitutto va creato il nostro record:

type
TWindowPos = packed record
hwnd: HWND;
hwndInsertAfter: HWND;
x: Integer;
y: Integer;
cx: Integer;
cy: Integer;
flags: UINT;
end;

Dopodiché si crea la funzione che si aggancia ai messaggi di Windows che controllano la posizione della finestra.

-------------------------------------

... //interface

private
   procedure WMWINDOWPOSCHANGING(var Msg: TWMWINDOWPOSCHANGING) ; message WM_WINDOWPOSCHANGING;

...//implementation

procedure TForm1.WMWINDOWPOSCHANGING(var Msg: TWMWINDOWPOSCHANGING);
var
Docked: Boolean;
rWorkArea: TRect;
StickAt : Word;
begin
StickAt := 20; //20 PIXELS
Docked := FALSE;

SystemParametersInfo(SPI_GETWORKAREA, 0, @rWorkArea, 0) ;

with Msg.WindowPos^ do
begin
    if x <= rWorkArea.Left + StickAt then
    begin
      x := rWorkArea.Left;
      Docked := TRUE;
    end;

    if x + cx >= rWorkArea.Right - StickAt then
    begin
      x := rWorkArea.Right - cx;
      Docked := TRUE;
    end;

    if y <= rWorkArea.Top + StickAt then
    begin
      y := rWorkArea.Top;
      Docked := TRUE;
    end;

    if y + cy >= rWorkArea.Bottom - StickAt then
    begin
      y := rWorkArea.Bottom - cy;
      Docked := TRUE;
    end;

    if Docked then
    begin
      with rWorkArea do
      begin
        // no moving out of the screen
        if x < Left then x := Left;
        if x + cx > Right then x := Right - cx;
        if y < Top then y := Top;
        if y + cy > Bottom then y := Bottom - cy;
      end; {with rWorkArea}
    end; {if Docked}
end; {with Msg.WindowPos^}

inherited;
end;

-------------------------------------

Ora è sufficiente eseguire il progetto ed avvicinare la finestra ai bordi dello schermo per ottenere il risultato desiderato.

 

 Contatto immediato

Contattato ( 23 )

 
 Tramite questo Modulo potrà contattare immediatamente il destinatario
 

Nome   

Cognome   

La sua E-mail   

Oggetto   

Richiesta   

 
 

 

Powered by www.youngportal.it

Copyright 2004 - Youngportal.it - Tutti i diritti riservati