首页  编辑  

动态显示窗口最小化过程

Tags: /超级猛料/API.Windows应用程序接口/窗口和控件相关/   Date Created:

画一个窗口动画:DrawAnimatedRects() API

下面的代码演示了动画显示最小化过程,缩小到系统Tray的:

procedure TForm1 . Button1Click ( Sender : TObject );

var

 FormRect , TrayRect : TRect ;

 hTray             : THandle ;

begin

  // Get handle of tray window

 hTray := FindWindowEx ( FindWindow ( 'Shell_TrayWnd' , nil ), 0 , 'TrayNotifyWnd' , nil );

  if hTray <> 0 then

  begin

    // This is the source rect for the animation.

   FormRect := BoundsRect ;

    // Get tray window's coordinates as a TRect. This will be the animation's destination rect.

   GetWindowRect ( hTray , TrayRect );

    {

     Now perform the actual animation. Note that this code only shows the

     animation. It does NOT minimize this application to the tray. I leave

     that up to yourself ;-)

     Also notice that the Delphi Help documents are very wrong about this

     function! Use the official MSDN docs located Microsoft's website.

     Instead of IDANI_CAPTION you can also use IDANI_OPEN and IDANI_CLOSE, but

     they don't seem to do anything... Maybe they are for future use?

   }

    if not DrawAnimatedRects ( Handle , IDANI_CAPTION , FormRect , TrayRect ) then

    begin

     MessageDlg ( 'DrawAnimatedRects() failed!' , mtError , [ mbOK ], 0 );

    end ;

  end

  else

  begin

   MessageDlg ( 'Can''t get tray window handle!' , mtError , [ mbOK ], 0 );

  end ;

end ;

最小化到任务栏:

procedure TForm1 . Button1Click ( Sender : TObject );

var

 FormRect , TrayRect : TRect ;

 hTray             : THandle ;

begin

  // Get handle of tray window

//  hTray := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'TrayNotifyWnd', nil);

 hTray := FindWindowEx ( FindWindow ( 'Shell_TrayWnd' , nil ), 0 , 'ReBarWindow32' , nil );

 hTray := FindWindowEx ( hTray , 0 , 'MSTaskSwWClass' , nil );

 hTray := FindWindowEx ( hTray , 0 , 'SysTabControl32' , nil );

  if hTray <> 0 then

  begin

    // This is the source rect for the animation.

   FormRect := BoundsRect ;

    // Get tray window's coordinates as a TRect. This will be the animation's destination rect.

   GetWindowRect ( hTray , TrayRect );

    {

     Now perform the actual animation. Note that this code only shows the

     animation. It does NOT minimize this application to the tray. I leave

     that up to yourself ;-)

     Also notice that the Delphi Help documents are very wrong about this

     function! Use the official MSDN docs located Microsoft's website.

     Instead of IDANI_CAPTION you can also use IDANI_OPEN and IDANI_CLOSE, but

     they don't seem to do anything... Maybe they are for future use?

   }

    if not DrawAnimatedRects ( Handle , IDANI_CAPTION , FormRect , TrayRect ) then

    begin

     MessageDlg ( 'DrawAnimatedRects() failed!' , mtError , [ mbOK ], 0 );

    end ;

  end

  else

  begin

   MessageDlg ( 'Can''t get tray window handle!' , mtError , [ mbOK ], 0 );

  end ;

end ;