Improve company productivity with a Business Account.Sign Up

x
?
Solved

Flashing application in the taskbar

Posted on 2004-08-12
14
Medium Priority
?
438 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:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…
Watch the video to know the process of migration of Exchange or Office 365 mailboxes in absence of MS Outlook. It is an eminent tool which can easily migrate Public, Archive user mailboxes from one another Exchange server and Office 365. Kernel Migr…

595 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