Mega Code Archive

 
Categories / Delphi / Forms
 

Moving a window from its client area

Title: Moving a window from its client area Question: This piece of code moves a window by draging it from the client area. Answer: //--------------------------------------------------------------------------- // Author : Digital Survivor [Esteban Rodrguez Nieto | Jos Plano] // Email : plmad666@gmail.com | jose.plano@gmail.com // Web site : www.ds-studios.com.ar //--------------------------------------------------------------------------- Unit DragClient; Interface Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; Type TForm1 = Class (TForm) Procedure FormMouseDown (Sender : TObject; Button: TMouseButton; Shift : TShiftState; X, Y : Integer); Procedure FormMouseMove (Sender : TObject; Shift : TShiftState; X, Y : Integer); Public { Public declarations } MoveWin : Boolean; Procedure Moved (Var Info); Message WM_MOVE; End; Var Form1 : TForm1; Implementation {$R *.DFM} Procedure TForm1.Moved (Var Info); Begin MoveWin := False; End; Procedure TForm1.FormMouseDown (Sender : TObject; Button : TMouseButton; Shift : TShiftState; X, Y : Integer); Begin If Button = mbLeft Then Begin MoveWin := True; SendMessage (Handle, WM_LButtonUp, 0, 0); SendMessage (Handle, WM_NCLButtonDown, HTCAPTION, 0); End; End; Procedure TForm1.FormMouseMove (Sender : TObject; Shift : TShiftState; X, Y : Integer); Begin If MoveWin Then SendMessage (Handle, WM_NCHITTEST, 2, 0); End; End.