⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 类似QQ的磁性界面,碰到屏幕边缘就自动隐藏
💻 ~PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls,Math;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    FAnchors: TAnchors;
    procedure WMMOVING(var Msg: TMessage);message WM_MOVING;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.WMMOVING(var Msg: TMessage);
begin 
  inherited;
  with PRect(Msg.LParam)^ do
  begin
    Left := Min(Max(0, Left), Screen.Width - Width);
    Top := Min(Max(0, Top), Screen.Height - Height);
    Right := Min(Max(Width, Right), Screen.Width);
    Bottom := Min(Max(Height, Bottom), Screen.Height);
    FAnchors := [];
    if Left = 0 then Include(FAnchors, akLeft);
    if Right = Screen.Width then
      Include(FAnchors, akRight);
    if Top = 0 then Include(FAnchors, akTop);
    if Bottom = Screen.Height then
      Include(FAnchors, akBottom);
      Timer1.Enabled := FAnchors <> [];
    end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
const 
  cOffset = 2;
  begin
    if WindowFromPoint(Mouse.CursorPos) = Handle then
    begin
      if akLeft in FAnchors then Left := 0;
      if akTop in FAnchors then Top := 0;
      if akRight in FAnchors then
        Left := Screen.Width - Width;
      if akBottom in FAnchors then
        Top := Screen.Height - Height;
      end else
      begin
        if akLeft in FAnchors then Left := -Width + cOffset;
        if akTop in FAnchors then Top := -Height + cOffset;
        if akRight in FAnchors then
          Left := Screen.Width - cOffset;
        if akBottom in FAnchors then
          Top := Screen.Height - cOffset;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Enabled := False;
  Timer1.Interval := 200;
  FormStyle := fsStayOnTop;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -