在什么事件里写?当鼠标拖动程序的标题栏重新定位后松开鼠标,会触发什么事件?应该怎么捕捉?

解决方案 »

  1.   

    自己写mouseleave,然后根据Form的尺寸和Form的位置来做
      

  2.   

    请教楼上的,用mouseleave有时不好使,怎么解决?
      

  3.   

    // Form zswang ,CSDN 一位值得尊敬的前辈unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Timer1: TTimer;
        Memo1: TMemo;
        procedure FormCreate(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
        FAnchors: TAnchors;
        procedure WMMOVING(var Msg: TMessage); message WM_MOVING;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}uses Math;procedure TForm1.WMMOVING(var Msg: TMessage);
    begin
      inherited;
      with PRect(Msg.LParam)^ do begin
        Left := Min(Max(0, Left), Screen.Width - Width);
        Top := Min(Max(0, Top), Screen.Height - Height);
        Right := Min(Max(Width, Right), Screen.Width);
        Bottom := Min(Max(Height, Bottom), Screen.Height);
        FAnchors := [];
        if Left = 0 then Include(FAnchors, akLeft);
        if Right = Screen.Width then Include(FAnchors, akRight);
        if Top = 0 then Include(FAnchors, akTop);
        if Bottom = Screen.Height then Include(FAnchors, akBottom);
        Timer1.Enabled := FAnchors <> [];
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Timer1.Enabled := False;
      Timer1.Interval := 200;
      FormStyle := fsStayOnTop;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    const
      cOffset = 2;
    var
      vHandle: THandle;
    begin
      vHandle := WindowFromPoint(Mouse.CursorPos);
      while (vHandle <> 0) and (vHandle <> Handle) do
        vHandle := GetParent(vHandle);
      if vHandle = Handle then begin
        if akLeft in FAnchors then Left := 0;
        if akTop in FAnchors then Top := 0;
        if akRight in FAnchors then Left := Screen.Width - Width;
        if akBottom in FAnchors then Top := Screen.Height - Height;
      end else begin
        if akLeft in FAnchors then Left := -Width + cOffset;
        if akTop in FAnchors then Top := -Height + cOffset;
        if akRight in FAnchors then Left := Screen.Width - cOffset;
        if akBottom in FAnchors then Top := Screen.Height - cOffset;
      end;
    end;end.
      

  4.   

    哇! Storm2008($$天冰$$) ,又是你啊!TreeView的拖动操作搞定了嘛?一会瞧瞧去。
    procedure MyMouseLeave(var message:TMessage);message  CM_MOUSELEAVE;
    对不起,有时不好使,我也不知道为什么:(
      

  5.   

    ----------------------------------------------------------------------
    没搞定啊:(OleDragDrop组件只能获得网页中的URL,对于ie地址栏中的地址不好使
    -----------------------------------------------------------------其实我的问题可以改为:如何通过拖拽将ie地址栏中的地址和标题保存到文件中
      

  6.   

    to  wjlsmail(计算机质子) 贴的代码好象不是楼主要的效果
      

  7.   

    建议楼主用timer控件,不过比较消耗系统资源
      

  8.   

    timer???实时判断Form位置吗?
      

  9.   

    唉,现在我也蒙~csdn,DFW都问了,也没个满意的答复
      

  10.   

    DFW我都好久不去了,下面是我查到的:
    没有办法,wm_mouseleave 消息的确是不好使:-(
    用 WM_NCHITTEST 好了,虽然麻烦点,但很准:-)
    mouseleav消息只是在鼠标在移出窗体的一瞬间被触发,如果移到了别的应用程序,消息是不能被捕获的
      

  11.   

    谢谢 今天刚用了一下WM_NCHITTEST
      

  12.   

    to Storm2008($$天冰$$)问题解决了?