Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Flashing application in the taskbar

Posted on 2004-08-12
14
Medium Priority
?
420 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:
Fahad Mukhtar earned 450 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:Fahad Mukhtar
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:Fahad Mukhtar
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:Fahad Mukhtar
ID: 11793989
yeah , put the stop flashing code in the Form_Activated event ;-)
0
 
LVL 19

Expert Comment

by:Fahad Mukhtar
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 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