C# win32 api入门--自制窗口闪烁效果与模态窗体闪烁效果

参考:http://zhidao.baidu.com/link?url=u21fWCzb6uPuayvsL4xQO2HxkGiX8E1Tuhc61kulKwJ7ETwnVLOLtqmFns_O7ieoatni0wcCyGUb_W6ULvVcR3q4phsz5oEboIwWfqLgIvu

http://blog.csdn.net/testcs_dn/article/details/45146025

 

今天突然感觉windows自带的模态窗口闪烁的时候闪太久,就找了一下怎么实现这个效果,比较一下

Form1

代码:

    public partial class Form1 : Form
    {
        ///


        /// 闪烁窗口
        ///

        /// 窗口闪烁信息结构
        ///
        [DllImport("user32.dll")]
        public static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 fm2 = new Form2();
            fm2.Show();
            //调用

            System.Media.SystemSounds.Beep.Play();//提示音
            FlashWindowEx(fm2.Handle, flashType.FLASHW_ALL|flashType.FLASHW_TIMER);
        }

        ///


        /// 闪烁窗口
        ///

        /// 窗口句柄
        /// 闪烁类型
        ///
        public static bool FlashWindowEx(IntPtr hWnd, flashType type)
        {
            FLASHWINFO fInfo = new FLASHWINFO();
            fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
            fInfo.hwnd = hWnd;//要闪烁的窗口的句柄,该窗口可以是打开的或最小化的
            fInfo.dwFlags = (uint)type;//闪烁的类型
            fInfo.uCount = 5;//闪烁窗口的次数主要改这个和下面的
            fInfo.dwTimeout = 80; //窗口闪烁的频度,毫秒为单位;若该值为0,则为默认图标的闪烁频度
            return FlashWindowEx(ref fInfo);
        }
        ///
        /// 闪烁类型
        ///

        public enum flashType : uint
        {
            FLASHW_STOP = 0, //停止闪烁
            FALSHW_CAPTION = 1, //只闪烁标题
            FLASHW_TRAY = 2, //只闪烁任务栏
            FLASHW_ALL = 3, //标题和任务栏同时闪烁
            FLASHW_PARAM1 = 4,
            FLASHW_PARAM2 = 12,
            FLASHW_TIMER = FLASHW_TRAY | FLASHW_PARAM1, //无条件闪烁任务栏直到发送停止标志或者窗口被激活,如果未激活,停止时高亮
            FLASHW_TIMERNOFG = FLASHW_TRAY | FLASHW_PARAM2 //未激活时闪烁任务栏直到发送停止标志或者窗体被激活,停止后高亮
        }
        ///
        /// 包含系统应在指定时间内闪烁窗口次数和闪烁状态的信息
        ///

        public struct FLASHWINFO
        {
            ///
            /// 结构大小
            ///

            public uint cbSize;
            ///
            /// 要闪烁或停止的窗口句柄
            ///

            public IntPtr hwnd;
            ///
            /// 闪烁的类型
            ///

            public uint dwFlags;
            ///
            /// 闪烁窗口的次数
            ///

            public uint uCount;
            ///
            /// 窗口闪烁的频度,毫秒为单位;若该值为0,则为默认图标的闪烁频度
            ///

            public uint dwTimeout;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 fm2 = new Form2();
            fm2.ShowDialog();
        }

你可能感兴趣的:(C#,c#,win32)