Solved

Flashing application in the taskbar

Posted on 2004-08-12
14
400 Views
Last Modified: 2012-08-13
How do I flash the application title in the taskbar?
0
Comment
Question by:zoobird
  • 6
  • 5
  • 3
14 Comments
 
LVL 8

Expert Comment

by:AaronReams
Comment Utility
// Add this to the top of the file
using System.Runtime.InteropServices;

// Add this to your class
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int FlashWindow(int hwnd, int bInvert);

// Call this from within your class to flash the window once
FlashWindow((Int32)this.Handle,1);
0
 
LVL 19

Accepted Solution

by:
Desp earned 150 total points
Comment Utility
hi,

To flash the window, you will have to call either the FlashWindow or
FlashWindowEx API functions.  The declarations are as follows:

using System.Runtime.InteropServices;
............
public const int FLASHW_STOP = 0;
public const int FLASHW_CAPTION = 0x00000001;
public const int FLASHW_TRAY = 0x00000002;
public const int FLASHW_ALL = (FLASHW_CAPTION | FLASHW_TRAY);
public const int FLASHW_TIMER = 0x00000004;
public const int FLASHW_TIMERNOFG = 0x0000000C;

[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
  [MarshalAs(UnmanagedType.U4)]
  public int cbSize;
  public IntPtr hwnd;
  [MarshalAs(UnmanagedType.U4)]
  public int dwFlags;
  [MarshalAs(UnmanagedType.U4)]
  public int uCount;
  [MarshalAs(UnmanagedType.U4)]
  public int dwTimeout;
}

[DllImport("user32.dll")]
public static extern bool FlashWindowEx([MarshalAs(UnmanagedType.Struct)]
ref FLASHWINFO pfwi);  

To use this api: (To blink that window)... put this code

FLASHWINFO f = new  FLASHWINFO();              
f.hwnd=this.Handle;  
f.dwTimeout=0;
f.dwFlags = FLASHW_ALL;
f.cbSize = Marshal.SizeOf( f);
f.uCount=100;
FlashWindowEx( ref f);


 
0
 

Author Comment

by:zoobird
Comment Utility
hooray!  it works!  thanks.  

i do need to know when the user has clicked on the flashing button so i can stop it from flashing.  how do i do this?
0
 
LVL 19

Expert Comment

by:Desp
Comment Utility
whom are you asking to?
when the application will get the focus it will no more blink!!
0
 

Author Comment

by:zoobird
Comment Utility
Desp, it still blinks.
0
 
LVL 19

Expert Comment

by:Desp
Comment Utility
//START Blinking
            private void button1_Click(object sender, System.EventArgs e)            
            {                  
                  FLASHWINFO f = new  FLASHWINFO();              
                  f.hwnd=this.Handle;  
                  f.dwTimeout=0;
                  f.dwFlags = FLASHW_ALL;
                  f.cbSize = Marshal.SizeOf( f);
                  f.uCount=100;
                  FlashWindowEx( ref f);
            }

//STOP Blinking
            private void button2_Click(object sender, System.EventArgs e)
            {
                  FLASHWINFO f = new  FLASHWINFO();              
                  f.hwnd=this.Handle;  
                  f.dwTimeout=0;
                  f.dwFlags = FLASHW_STOP;
                  f.cbSize = Marshal.SizeOf( f);
                  f.uCount=100;
                  FlashWindowEx( ref f);
            }
0
 

Author Comment

by:zoobird
Comment Utility
Thanks for your help Desp I really appreciate it and will definitely award you with the points.  Is there any way to stop the blinking when the user clicks on the flashing button at the taskbar?  
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 19

Expert Comment

by:Desp
Comment Utility
yeah , put the stop flashing code in the Form_Activated event ;-)
0
 
LVL 19

Expert Comment

by:Desp
Comment Utility
anymore questions?
0
 

Author Comment

by:zoobird
Comment Utility
is there any way to know whether the button is already blinking or if FlashWindowEx is active?
0
 
LVL 8

Expert Comment

by:AaronReams
Comment Utility
gee, thanks.
0
 

Author Comment

by:zoobird
Comment Utility
Aaron, I will reward you the same number of points.  I will post a question with title,"Points for AaronReams".  Thanks for your help too.
0
 

Author Comment

by:zoobird
Comment Utility
Aaron, would you know how to detect whether the button is blinking?
0
 
LVL 8

Expert Comment

by:AaronReams
Comment Utility
Hi zoobird,

Thanx.  I'm not sure of the best way to detect if the button is blinking.  It just depends on how you are using it.  There's a few different options...

You could maintain state on your own with a bool in your class.

You can always just call FlashWindow(this.Handle, false) to disable the flashing and return to its original state (active or inactive).

You can also check the state of FlashWindow using the return type.

<MSDN>
The return value specifies the window's state before the call to the FlashWindow function. If the window caption was drawn as active before the call, the return value is nonzero. Otherwise, the return value is zero.

Good luck.
-Aaron
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now