我用DELPHI做播放器时怎样才能做出像WINAMP中那种当窗口靠近另一窗口时会自动吸附的效果呢?在VC里看到做这种吸附窗口效果不是很难,不知道我用两个FORM能不能做出来。请大家帮帮忙,谢谢了!

解决方案 »

  1.   

    拦截WM_MOVE消息即可
    type
      TForm1 = class(TForm)
      private
      procedure WMMOVE(var Msg: TMessage); message WM_MOVE;
      end;
    var
      Form1: TForm1;
    implementation
    {$R *.DFM}{ TForm1 }procedure TForm1.WMMOVE(var Msg: TMessage);
    begin
      Inherited;
      if (Left < 10) and (Top < 10) and 
      (Left <> 0) and (Top <> 0) then // 设定移动到左上角 10 点范围内时贴到边上去
      begin
         Left := 0;
         Top := 0;
         Msg.Result := 0;
      end;
    end;
    这只是最简单的
    作多个窗体相互吸引也是同样的道理,这就是磁性窗体的实现原理
    不过会有些bug,就是在相互吸引的范围内如果你用鼠标拖住窗体,会出现窗体的抖动,这个问题我也没办法解决
      

  2.   

    跟楼上一样的方法http://awin.y365.com/prg/prg29.html
    VC的http://www.csdn.net/magazine/sourcecode/Topic/0/28.shtm
    BCB的http://bdn.borland.com/article/0,1410,26370,00.html
    桌面的吸附窗口效果http://delphi.icm.edu.pl/ftp/d30free/magform.zip