Move borderless form in Firemonkey

2019-03-05 02:59发布

In VCL forms I use WM_SYSCOMMAND, but in firemonkey it is undeclared.

I test this code:

procedure TForm4.dragPanelMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  isDraging := true;
  X0 := X;
  Y0 := Y;
end;

procedure TForm4.dragPanelMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Single);
begin
  if isDraging then
  begin
    Form4.Left := Trunc(Form4.Left + X - X0);
    Form4.Top := Trunc(Form4.Top + Y - Y0);
  end;
end;

procedure TForm4.dragPanelMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  isDraging := False;
end;

this works, but just for slow moves!!!

How can I move form in Firemonkey?

2条回答
等我变得足够好
2楼-- · 2019-03-05 03:38

What easier is just to use the StartWindowDrag method of the Form. This way it will work in both Windows and MacOS and its only 1 line of code. Like so:

procedure TForm4.dragPanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
    Self.StartWindowDrag;
end;
查看更多
爷的心禁止访问
3楼-- · 2019-03-05 04:01

If the VCL code that you want to replicate is:

SendMessage(MyForm.Handle, WM_SYSCOMMAND, SC_DRAGMOVE, 0);

then the equivalent for FMX would be:

SendMessage(FmxHandleToHWND(MyForm.Handle), WM_SYSCOMMAND, SC_DRAGMOVE, 0);

The reason is that MyForm.Handle is an FMX handle. That's not the same as a window handle. You convert to a window handle with FmxHandleToHWND().

You may need to declare a couple of constants:

const
  WM_SYSCOMMAND = $0112;
  SC_DRAGMOVE = $F012;
查看更多
登录 后发表回答