Do not know that everyone in the use of QQ did not think of its indentation out of the function is how to achieve it? The key to achieving this effect is to determine whether the form below the current mouse pointer is our program form. GetCursorPos () is an API function that gets the coordinates of the mouse pointer in the screen, using it with Findvclwindow () to easily get the VCL visual component under the mouse pointer, but when there is more than one VCL visual component in a form, For example, there may be tpanel, TMemo, and so on, so we have to find their parent level and eventually get tform, which means our program form. In this way, I've customized the Getformnameat () function, which gets the name of the form under the current mouse pointer. The main implementation code of the program is listed below for your reference:
Custom function Getformnameat to get the name of the form under the mouse pin
function Getformnameat (X, Y:integer): string;
Var
P:tpoint;
W:twincontrol;
Begin
p.x: = X;
P.Y: = Y;
W: = Findvclwindow (P); Get the VCL visual component under the mouse pointer
if (nil <> W) then
Begin
While W.parent<>nil does//when the superior parent of W is not empty, continue to look up
W:=w.parent;
Result: = w.name;//finally returns the name of the form
End
Else
Begin
Result: = ';
End
End
Procedure Tform1.timer1timer (Sender:tobject);
Var
Winpos:tpoint;
Begin
if (Form1. top<=3) or (Form1. Left>=screen. WIDTH-FORM1.WIDTH-3) then//judgment
Begin
GetCursorPos (Winpos); Gets the coordinates of the current mouse pointer on the screen
When the name of the form under the mouse pointer equals form1.name
If Form1.name=getformnameat (Winpos. X,winpos. Y) Then
{Here we can get a special name for Form1 in case a different form name is the same as it}
Begin
Form1. Timer2.enabled:=false; Deactivate Timer2
Form1. top:=0; The top of the Form1 is aligned with the screen
End
Else
Form1. Timer2.enabled:=true; Open Timer2
End
End
Procedure Tform1.timer2timer (Sender:tobject);
Begin
If Form1. Top<=20 Then
Form1. Top:=-(Form1. HEIGHT-10)//move Form1 up, exposing 10 pixels above the screen
End