zhanger's picture

Flashing the taskbar GameWindow icon

Hello, I need to flash the taskbar icon (on windows, where the icon on the bottom blinks yellow) when a certain event occurs within my game while it is not in focus, but can't seem to get much luck doing it. I found this stackoverflow article which has a utility class for it but the main method has a parameter of a System.Windows.Form -

        public static bool Flash(System.Windows.Forms.Form form)
        {
            // Make sure we're running under Windows 2000 or later
            if (Win2000OrLater)
            {
                FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL | FLASHW_TIMERNOFG, uint.MaxValue, 0);
                return FlashWindowEx(ref fi);
            }
            return false;
        }

I've modified it instead so it just uses an IntPtr (a handle) instead -

        public static bool Flash(IntPtr handle)
        {
            if (Win2000OrLater)
            {
                FLASHWINFO fi = Create_FLASHWINFO(handle, FLASHW_ALL | FLASHW_TIMERNOFG, uint.MaxValue, 0);
                return FlashWindowEx(ref fi);
            }
            return false;
        }

However, my problem then was getting the handle of the the GameWindow. I found this snippet on the forums at http://www.opentk.com/node/1221 -

            IWindowInfo ii = ((OpenTK.NativeWindow)this).WindowInfo;
            object inf = ((OpenTK.NativeWindow)this).WindowInfo;
            PropertyInfo pi = (inf.GetType()).GetProperty("WindowHandle");
            IntPtr hnd = ((IntPtr)pi.GetValue(ii, null));

However, calling Flash with the IntPtr from that results in nothing; the method returns false. I've been searching for a while with not much findings; if any help could be given on how to flash the gamewindow in the taskbar, it would be much appreciated.