I don't know how the scaled-out function was realized when I used QQ? The key to achieving this effect is how to determine whether the form below the current mouse pointer is our program form. GetCursorPos () is an API function that obtains the coordinates of the mouse pointer on the screen. It can be used with FindVCLWindow () to easily obtain the VCL visual component under the mouse pointer.
However, when there are more than one VCL visual component in a form, such as TPanel and TMemo, we must find their Parent level and finally get the TForm, it refers to our program form. According to this idea, I have customized the GetFormNameAt () function, which can get the name of the form under the current mouse pointer. The main implementation code of the program is listed below for your reference:
// The custom function GetFormNameAt obtains the Name of the form pointed by the mouse needle.
Function GetFormNameAt (X, Y: integer): string;
Var
P: TPoint;
W: TWinControl;
Begin
P. X: = X;
P. Y: = Y;
W: = FindVCLWindow (P); // obtain the VCL visual component under the mouse pointer.
If (nil <> W) then
Begin
While w. Parent <> nil do // when W's Parent is not empty, continue searching
W: = w. Parent;
Result: = W. Name; // The Name Of The final returned form.
End
Else
Begin
Result: = '';
End;
End;
Procedure TForm1.Timer1Timer (Sender: TObject );
Var
WinPos: TPoint;
Begin
GetCursorPos (winpos); // obtain the coordinates of the current mouse pointer on the screen
// When the Name of the form under the mouse pointer is form1.name
If form1.name = GetFormNameAt (winpos. X, winpos. Y) then
{Here we can take a special name for form1 to prevent other forms from being the same as it}
Begin
Form1.Timer2. Enabled: = false; // disable Timer2
Form1.Top: = 0; // the Top of form1 is aligned with the screen
End
Else
Form1.Timer2. Enabled: = true; // enable Timer2
End;
Procedure TForm1.Timer2Timer (Sender: TObject );
Begin
If form1.Top <= 20 then
Form1.Top: =-(form1.Height-10); // move form1 up, 10 pixels above the screen
End;