看看delphi自己本身的screensnap怎么做的吧。
procedure TCustomForm.WMWindowPosChanging(var Message: TWMWindowPosChanging);
procedure HandleEdge(var Edge: Integer
SnapToEdge: Integer;
SnapDistance: Integer = 0);
begin
if (Abs(Edge + SnapDistance - SnapToEdge) < FSnapBuffer) then
Edge := SnapToEdge - SnapDistance;
end;
begin
if FScreenSnap and ((Message.WindowPos^.X <> 0) or (Message.WindowPos^.Y <> 0)) then
with Message.WindowPos^, Monitor.WorkareaRect do
begin
HandleEdge(x, Left, Monitor.WorkareaRect.Left);
HandleEdge(y, Top, Monitor.WorkareaRect.Top);
HandleEdge(x, Right, Width);
HandleEdge(y, Bottom, Height);
end;
inherited;
end;