Solved

Flashing application in the taskbar

Posted on 2004-08-12
14
404 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
ID: 11789302
// 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
ID: 11790606
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
ID: 11792724
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 19

Expert Comment

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

Author Comment

by:zoobird
ID: 11793586
Desp, it still blinks.
0
 
LVL 19

Expert Comment

by:Desp
ID: 11793743
//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
ID: 11793938
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
 
LVL 19

Expert Comment

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

Expert Comment

by:Desp
ID: 11794267
anymore questions?
0
 

Author Comment

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

Expert Comment

by:AaronReams
ID: 11795073
gee, thanks.
0
 

Author Comment

by:zoobird
ID: 11795639
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
ID: 11795654
Aaron, would you know how to detect whether the button is blinking?
0
 
LVL 8

Expert Comment

by:AaronReams
ID: 11797350
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

813 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

9 Experts available now in Live!

Get 1:1 Help Now