saptechnique

Better late than never. - 郭富

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

  声明方式:  

声明
    [DllImportAttribute("user32.dll")]
    private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);

  参数说明:

Code
    (1). IntPtr hwnd: 目标窗口的句柄对象, 一般为 this.Handle
    (2). int dwTime: 动画的持续时间, 数值越大动画效果的时间越长
   (3). int dwFlags: 动画效果类型选项, 在C#中声明如下:
     注: 您程序中只声明需要的动画类型即可, 关于每个参数的含义会在后面详细说明
    public const Int32 AW_HOR_POSITIVE = 0x00000001;
    public const Int32 AW_HOR_NEGATIVE = 0x00000002;
    public const Int32 AW_VER_POSITIVE = 0x00000004;
    public const Int32 AW_VER_NEGATIVE = 0x00000008;
    public const Int32 AW_CENTER = 0x00000010;
    public const Int32 AW_HIDE = 0x00010000;
    public const Int32 AW_ACTIVATE = 0x00020000;
    public const Int32 AW_SLIDE = 0x00040000;
    public const Int32 AW_BLEND = 0x00080000;

动画效果类型详细说明表:

  1. AW_SLIDE : 使用滑动类型, 默认为该类型. 当使用 AW_CENTER 效果时, 此效果被忽略

  2. AW_ACTIVE: 激活窗口, 在使用了 AW_HIDE 效果时不可使用此效果

  3. AW_BLEND: 使用淡入效果

  4. AW_HIDE: 隐藏窗口

  5. AW_CENTER: 与 AW_HIDE 效果配合使用则效果为窗口几内重叠, 单独使用窗口向外扩展.

  6. AW_HOR_POSITIVE : 自左向右显示窗口

  7. AW_HOR_NEGATIVE: 自右向左显示窗口

  8. AW_VER_POSITVE: 自顶向下显示窗口

  9. AW_VER_NEGATIVE : 自下向上显示窗口

  看懂了这些, 下面我们的工作会变得非常简单.

  启动程序后, 动画效果显示窗口的代码如下:

Code
AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_CENTER);

  而关闭程序后, 动画效果显示窗口代码如下:

Code
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
      AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);
    }

  程序的完整代码如下:

Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FalshWindows
{
  public partial class Form1 : Form
  {
    [DllImportAttribute("user32.dll")]
    private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
    public const Int32 AW_HOR_POSITIVE = 0x00000001;
    public const Int32 AW_HOR_NEGATIVE = 0x00000002;
    public const Int32 AW_VER_POSITIVE = 0x00000004;
    public const Int32 AW_VER_NEGATIVE = 0x00000008;
    public const Int32 AW_CENTER = 0x00000010;
    public const Int32 AW_HIDE = 0x00010000;
    public const Int32 AW_ACTIVATE = 0x00020000;
    public const Int32 AW_SLIDE = 0x00040000;
    public const Int32 AW_BLEND = 0x00080000;
    public Form1()
    {
      InitializeComponent();
      AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_CENTER);
    }
    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
      AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);
    }
  }
}

posted on 2010-03-08 15:58  guofu  阅读(426)  评论(1编辑  收藏  举报