How to drop an object from the form window beyond all the windows of its program? For example, on the desktop or somewhere else. In fact, it’s “to what” to drop, at this stage it doesn’t matter to me, but it’s important to “where” - i.e. mouse coordinates (global) when the button is released. I need to open a new window in this place (with the content dropped).
Two years ago I had a very interesting group of students, we together wrote a program for processing these mutations. Since the intended audience of the users of this program are people who are not very computer savvy, the creators wanted to simplify data input and output: the 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 options were invented:
Most advanced : set a global hook using
SetWindowsHookEx and writing a DLL for catching the mouse button and returning the coordinates of the cursor.
The most original : create a transparent form on the whole screen, and on top - already working with the property AlwaysOnTop
The laziest : when you need to pick up or send data, turn on the timer, which every 50 milliseconds saves the global coordinates of the cursor to a variable, and turns off 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;