1
votes

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
You can use WM_SYSCOMMAND too. It it's not defined, define it.David Heffernan
How I can define WM_SYSCOMMAND?sma6871
@David, I think the only magic in the so called SC_DRAGMOVE constant is that MS just forget to include it to the winuser header file (and because of this also document it). I don't think it's magical somehow. sma6871, try the code like this and optionally move the constants to be common.TLama
@TLama My problem is the use of $F012. Using SC_DRAGMOVE is fine. And your code is for VCL. The Q is FMX.David Heffernan

2 Answers

2
votes

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;
11
votes

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;