鼠标左键在界面内任意处按下后可以移动窗体用响应WM_NCHITTEST来实现:
  procedure TfrmMain.WMNCHitTest(var Msg: TWMNCHitTest);
  begin
  inherited;
  if Msg.Result = htClient then
    Msg.Result  := htCaption;
  end;
  a.请问其中机理是什么?这样从TWMNCHitTest到Msg.Result?(50分)
  b.如果我的form上有panel,如何让鼠标左键在panel上按下后也可以移动窗体?(50分)

解决方案 »

  1.   

    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
        ReleaseCapture;
        Perform(WM_SYSCOMMAND, $F012, 0);
    end;
      

  2.   

    a)原理就是你的代码正在欺骗Windows,即在鼠标点击Windows Form的时候,告诉Windows,你点击到的位置是Caption,而鼠标点击Caption是可以移动窗体位置的。
      

  3.   

    b)斑竹答了方法最简单了。如果用同样的方法,需要继承Panel,在Panel内写这个方法就可以了。
      

  4.   

    procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if Button=mbLeft then
      begin
        ReleaseCapture;
        SendMessage(Handle,WM_SYSCOMMAND,$F012,0);
      end;
    end;
      

  5.   

    blazingfire(烈焰), windindance(风舞轻扬)答案确实正确,可是为什么?
    $f012,$f017都可以,可是在messages.pas,MSDN中都找不到对应的参数解释?