Solved

Flashing application in the taskbar

Posted on 2004-08-12
14
410 Views
Last Modified: 2012-08-13
How do I flash the application title in the taskbar?
0
Comment
Question by:zoobird
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

696 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