自定义拖动后Delphi窗口失去焦点

时间:2013-04-04 21:04:29

标签: delphi drag-and-drop

当我拖动MyThingThatDragsIt

时,我有这个代码可以移动我的主窗口
procedure TMainForm.ApplicationMessage(var Msg: TMsg; var Handled: Boolean);
var
  ScreenPt : TPoint;
  DragControl : TControl;

begin
  inherited;
  if Msg.message = WM_LBUTTONDOWN then
  begin

    ScreenPt := ScreenToClient(Msg.pt);
    DragControl := FindDragTarget(Msg.pt , false);
    if Assigned(DragControl) and
      ((DragControl = MyThingThatDragsIt)
      ) then
    begin
      ReleaseCapture;
      self.Perform(WM_SYSCOMMAND, SC_MOVE or $0002, 0 );
    end;
  end
end;

这样可行,但是当我放手时,我的程序已经失去了它的焦点,我必须在表单上单击一次才能点击任何其他按钮。

知道这里有什么问题吗?我跟着steps from this question

1 个答案:

答案 0 :(得分:4)

告诉VCL您已经处理了这条消息:

  ...
  Perform(WM_SYSCOMMAND, SC_MOVE or $0002, 0 );
  Handled := True;
  ...