How do I drop an object from the form window to the outside?

How do I drop an object from the form window outside of all the windows of my program? For example, on the desktop or somewhere else. In fact," what "exactly to drop, at this stage it is not important to me, but it is important to "where" - i.e. the coordinates of the mouse (global) at the time of releasing the button. I need to open a new window in this place (with the dropped content).

Author: Viktor Tomilov, 2012-07-04

1 answers

Two years ago, I had a very interesting group of students, we jointly wrote a program for processing mutation data. Since the intended audience of users of this program is people who are not very computer-savvy, the creators wanted to simplify data input and output: data was "taken" from the desktop and sent to the desktop. There was a problem - how to get the coordinates of the mouse cursor outside the form.

As a result, several were invented options:

The most advanced: set a global hook by SetWindowsHookEx and writing a DLL for the function of catching the mouse button release and returning the cursor coordinates.

The most original: create a transparent form on the entire screen, and on top - already working with the AlwaysOnTop property

The laziest: when you need to pick up or send data, turn on the timer, which saves the global coordinates of the cursor every 50 milliseconds in variable, and is disabled when the mouse button is pressed. Code:

var
  object_cur_pos: TPoint;

<...>
procedure DataForm.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   <...>
   if ExternalCursorOn and MouseTimer.Enabled then MouseTimer.Enabled:=false; // прекратить отслеживание координат
   <...>
end;

procedure DataForm.MouseTimer(Sender: TObject);
begin
  GetCursorPos(object_cur_pos); // считать глобальные координаты курсора
end;
 1
Author: Viktor Tomilov, 2017-12-16 12:50:37