using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Ex01_11
{
    public partial class Form1 : Form
    {

        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;           //使用淡入效果

                           //声明AnimateWindow函数
        [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
                           //声明FlashWindow函数
        [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
        public static extern bool FlashWindow(IntPtr handle, bool bInvert);

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            AnimateWindow(this.Handle, 2000, AW_SLIDE + AW_HOR_POSITIVE);
        }

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

        private void timer1_Tick(object sender, EventArgs e)
        {
            FlashWindow(this.Handle, true);
        }

        private void Form1_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled)
               {
                  timer1.Enabled = false;
               }
            else
              {
                  timer1.Enabled = true;
              }
        }
    }
}
