Mega Code Archive

 
Categories / Delphi / Examples
 

How can i prevent the user from moving or sizing my form

Question: How can I prevent the user from moving or sizing my form? Answer: Trap the Windows WM_WINDOWPOSCHANGING message and "or" the flags of the WindowPos structure passed in the message's lparam parameter with the predefined constants SWP_NOMOVE and SWP_NOSIZE. Example: type TForm1 = class(TForm) private { Private declarations } procedure WMPosChange(var Message: TWMWINDOWPOSCHANGING); message WM_WINDOWPOSCHANGING; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure Tform1.WMPosChange(var Message: TWMWINDOWPOSCHANGING); begin PWindowPos(TMessage(Message).lParam).Flags := PWindowPos(TMessage(Message).lParam).Flags or SWP_NOMOVE or SWP_NOSIZE; end;