Delphi simulates QQ Form Scaling

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.