2

I've got this code that moves my Main Window around when I drag around 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;

That works OK, but when I let go, my program has lost it's focus and I've got to click once on the form just to click on any other buttons.

Any idea what is wrong here? I followed steps from this question

Community
  • 1
  • 1
Peter Turner
  • 11,199
  • 10
  • 68
  • 109

1 Answers1

4

Tell the VCL that you've taken care of the message:

  ...
  Perform(WM_SYSCOMMAND, SC_MOVE or $0002, 0 );
  Handled := True;
  ...
Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169