IIM Home

Screen Shots
Code Outline
C# Recipes
Contact Information

How do you make a window flash? Well there is no native way to do it in .Net.  Below is the code copied from the Chat Window code, comments and all.  Basically the code imports the two methods from user32.dll and then based on whether it's WinNT or Win2k or Higher is calls the appropriate flashing API.  NT doesn't have the FlashWindowEx method and will crash if you try to call it.

       /// <summary>
       /// The DLL Import to allow access to the FlashWindow.
       /// FlashWindowEx does not exist in NT. So we use FlashWindow
       /// </summary>
       /// <remarks>This may cause NT to fail to create a Conversation Window</remarks>
       public static extern bool FlashWindow(IntPtr hwnd, bool flash);

       public static extern bool FlashWindowEx(ref FLASHINFO fInfo);
       public struct FLASHINFO
             public Int32  cbSize;
             public IntPtr  hwnd;
             public int dwFlags;
             public UInt32  uCount;
             public int dwTimeout;
       public void FlashChatWindow()
              if (iimc.AdvancedFlashing)//Determined by if WinVer is 5+
              //  const int FLASHW_STOP = 0;  Not used so save some memory
                    const int FLASHW_CAPTION = 1;
                    const int FLASHW_TRAY = 2;
                    const int FLASHW_ALL = FLASHW_CAPTION | FLASHW_TRAY;
              //    const int FLASHW_TIMER = 4; Not used so save some memory
                    const int FLASHW_TIMERNOFG = 12;
                     FLASHINFO fInfo = new FLASHINFO();
                          fInfo.cbSize = sizeof(FLASHINFO);
                     fInfo.dwFlags = FLASHW_TIMERNOFG | FLASHW_ALL;
                     fInfo.hwnd = this.Handle;
                     fInfo.uCount = 5;
                     fInfo.dwTimeout = 0;
                     FlashWindowEx(ref fInfo);
                    ///Flash 3 times using FlashWindow
                    ///this is a really shitty way to do this, but I don't know how
                    ///else in Windows NT.
                    ///If anyone finds out a better way, let me know!
                    ///ctwoodward @ users.sourceforge.net
                    ///I hate GUI programming...
                     for (int i = 0; i<3;i++)
                           FlashWindow(this.Handle, true);
                    catch (Exception ex)
                     log.Debug("Exception while flashing the window:\n"+ex);

Home | Members | Archive | Discussions | Screen Shots | Code Outline | C# Recipes | Contact Information

 Copyright 2004 The Tiny Custom Software Company.
For problems or questions regarding this Web site contact Project Admin Email.
Last updated: 01/02/05.

Free Site Counters