0

I'm developing an application and it looks as if my Form object doesn't have anything for me to specify its exact coordinates.

I have a label at the top acting as a titlebar, in c# I could use a combination of my mouse coordinates and window coordinates to make the window move with the mouse when the user clicks and drags. However, in c++ (along side RAD studio) there doesn't appear to be anything online I can use as reference to pull this off.

I've tried windows api with:

SetWindowPos(this->GetOwnerWindow(), HWND_TOPMOST, 5,5,5,5, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

There's things like window position, but that only accepts integers or vars like "poScreenCenter".

Any insight on how this could be possible would be great.

Piero Bird
  • 119
  • 1
  • 10

1 Answers1

2

TForm (and all UI controls in general) have Left and Top (and Width and Height) properties.

You can use the Label's OnMouse(Down|Up) events to set/unset a bool, and then have the Label's OnMouseMove event reposition the Form if the bool is set.

A simpler and more efficient solution is to have the OnMouseDown event send an undocumented WM_COMMAND(SC_DRAGMOVE) message to the Form's HWND and let the OS handle the rest for you. See Moving a caption-less window by using a "drag area" (written for Delphi, but it applies to C++Builder too, since they use the same VCL framework).

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770