当把QQ拖到屏幕顶部或左右两边时,它的窗体会自动隐藏.
当该窗体失去焦点时,把鼠标移到窗体上面窗体又动画般的出来.这说明有当窗体没有焦点时也可以有代码在运行.请问这是怎么实现的?

解决方案 »

  1.   

    新建DELPHI群7322920欢迎大家加入,一起提高!
      

  2.   

    新建一个工程,在窗体上放一个Label(用来捕获MouseLeave事件),AutoSize:=False;align:=alClient;
    一个tiemr,enabled:=false;interval:=10;代码如下:
    procedure TForm1.Label1MouseLeave(Sender: TObject);
    begin
    timer1.Enabled := true;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      if form1.Left <> screen.Width-10 then
      form1.Left := form1.Left + 1;
    end;
      

  3.   

    转贴
    {  ***************可以实现类似QQ窗体的隐藏效果*******************  }
    {                        Design:  Kevin                }unit QQForm;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, Math;{$R QQfrm.res}type
      TQQForm = class(TComponent)
      private
        { Private declarations }
        fActive:Boolean;
        fOldWndMethod:TWndMethod;
        fForm:TForm;
        ftimer:TTimer;
        fAnchors: TAnchors;
      protected
        { Protected declarations }
      public
        { Public declarations }
        constructor Create(AOwner:TComponent); override;
        destructor Destroy; override;
        procedure WndProc(var Message: TMessage);
        procedure WMMoving(var Msg: TMessage);
        procedure fOnTimer(Sender: TObject);
        function FindParHWMD(Pos :TPoint):THandle;
      published
        { Published declarations }
        property Active:boolean  read fActive  write fActive;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Kevin', [TQQForm]);
    end;{ TQQForm }constructor TQQForm.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      fActive:=True;
      fTimer:=TTimer.Create(self);
      fForm:=TForm(AOwner);
      fForm.FormStyle := fsStayOnTop;
      fTimer.Enabled := True;
      fTimer.OnTimer := fOnTimer;
      fTimer.Interval := 200;
      fOldWndMethod:=fForm.WindowProc;
      fForm.WindowProc:=WndProc;
    end;destructor TQQForm.Destroy;
    begin
      FreeAndNil(fTimer);
      fForm.WindowProc:=fOldWndMethod;
      inherited Destroy;
    end;function TQQForm.FindParHWMD(Pos: TPoint): THandle;
    var
      WControl :TWinControl;
    begin
      WControl := FindVCLWindow(Pos);
      if WControl <> nil then
      begin
        while not (WControl.Parent = nil) do
        begin
          WControl := WControl.Parent;
        end;
        Result := WControl.Handle;
      end else Result := 0;
    end;procedure TQQForm.fOnTimer(Sender: TObject);
    const
      coffset = 3;
    var
      ParHandle :THandle;
    begin
      ParHandle := FindParHWMD(Mouse.CursorPos);
      if ParHandle = fForm.Handle then
      begin
        if akLeft in FAnchors then fForm.Left := 0;
        if akTop in FAnchors then fForm.Top := 0;
        if akRight in FAnchors then fForm.Left := Screen.Width - fForm.Width;
        if akBottom in FAnchors then fForm.Top := Screen.Height - fForm.Height;
      end else
      begin
        if akLeft in FAnchors then fForm.Left := -fForm.width + coffset;
        if akTop in FAnchors then fForm.Top := -fForm.Height + coffset;
        if akRight in FAnchors then fForm.Left := Screen.Width - coffset;
        if akBottom in FAnchors then fForm.Top := Screen.Height - coffset;
      end;
    end;procedure TQQForm.WMMoving(var Msg: TMessage);
    begin
      inherited;
      with PRect(msg.LParam)^ do
      begin
        Left := Min(Max(0,Left),Screen.Width - fForm.Width);
        Top := Min(Max(0,Top),Screen.Height - fForm.Height);
        Right := Min(Max(fForm.Width,Right),Screen.Width);
        Bottom := Min(Max(fForm.Height,Bottom),Screen.Height);    FAnchors := [];
        if Left = 0 then Include(FAnchors,akLeft);    if Right = Screen.Width then Include(FAnchors,akRight);    if (Top = 0) and (Left <> 0) and (Right <> Screen.Width) then
        begin
          Include(FAnchors,akTop);
        end else
        if Left = 0 then
        begin
          Include(FAnchors,akLeft);
        end else
        if Right = Screen.Width then
        begin
          Include(FAnchors,akRight);
        end;    if Bottom = Screen.Height then Include(FAnchors,akBottom);    fTimer.Enabled := FAnchors <> [];
      end;
    end;procedure TQQForm.WndProc(var Message: TMessage);
    begin
      if not fActive then
      begin
        fOldwndMethod(Message);
        Exit;
      end; 
      if (CsDesigning in ComponentState) then fOldwndMethod(Message)
      else
        case Message.Msg of
           WM_MOVING : WMMoving(Message);
        else fOldwndMethod(Message);
      end;
    end;end.
      

  4.   

    MoveWindow 和 ShowWindow就可以实现了,在delphi中可以直接调整left 和 top的值实现,主要是要做个鼠标钩子,也可以做个循环或者timer来检测鼠标位置,但效果不如钩子好。
      

  5.   

    这是伴水老大的帖子,你看看
    USE MATHunit  Unit1;  
     
    interface  
     
    uses  
       Windows,  Messages,  SysUtils,  Variants,  Classes,  Graphics,  Controls,  Forms,  
       Dialogs,  StdCtrls,  ExtCtrls;  
     
    type  
       TForm1  =  class(TForm)  
           Timer1:  TTimer;  
           procedure  FormCreate(Sender:  TObject);  
           procedure  Timer1Timer(Sender:  TObject);  
       private  
           {  Private  declarations  }  
           FAnchors:  TAnchors;  
           procedure  WMMOVING(var  Msg:  TMessage);  message  WM_MOVING;  
       public  
           {  Public  declarations  }  
       end;  
     
    var  
       Form1:  TForm1;  
     
    implementation  
     
    {$R  *.dfm}  
     
    uses  Math;  
     
    {  TForm1  }  
     
    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.FormCreate(Sender:  TObject);  
    begin  
       Timer1.Enabled  :=  False;  
       Timer1.Interval  :=  200;  
       FormStyle  :=  fsStayOnTop;  
    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;  
     
    end.