C # WinForm implement taskbar program icon Blink

Source: Internet
Author: User

I believe you will know when using QQ, you opened the QQ Chat window, if the window is not currently activated window, when the QQ message is received, the taskbar (not the tray icon) on the icon will flash into yellow (Win7 default theme), to inform the user that a message came in, before I used C # Do not know how this is done, with this. The Activate () method is to activate the form directly without achieving the desired effect. Later, two API functions were found to implement this function.
A Windows API function is used. Let's take a look at this function:

BOOL FlashWindow (  hwnd hwnd,     //  handle to Windows to Flash  BOOL binvert     Flash status);
View Code

The

uses the API function FlashWindow to blink the specified window, allowing the window to switch between the active and inactive states, It has two parameters: hwnd and Binvert. Where the parameter HWND is the window handle to blink, the parameter binvert is a bool variable, when set to True, the program window title bar switches from active to inactive, or reverse, when set to False, The window title bar reverts to its original state. If you mate with a time component (the Timer component), execute the statement at a certain interval of time. The

Call in C # is simple:

[DllImport ("User32.dll""flashwindow")] Private Static extern void BOOL  // direct call to FlashWindow can beFlashWindow (thistrue);
View Code

This can be achieved. This is relatively simple, there is another function, you can achieve the number of flashes.

BOOL WINAPI FlashWindowEx (  //Flash status information);

That's it.
Parameter description:
Pflashwinfo
Defined:

struct {  UINT  cbsize;     // the byte size  of the structure HWND  hwnd;      // The handle to the window to blink, which can be open or minimized  DWORD dwFlags;   // Flashing State  UINT  Ucount;    // Number of flashing windows  // The frequency of the window blink, in milliseconds, or the default icon if the value is 0 } Flashwinfo, *pflashwinfo;

Members:

DwFlags: // flashw_all-------0x00000003 a taskbar button that blinks both the window title and the window, equivalent to Falshw_caption | Flashw_tray//flashw_caption---0x00000001 blinking window title //flashw_stop------0 Stop blinking, The system resets the window to its initial state //flashw_timer-----0x00000004 flashes continuously until the FLASHW_STOP flag is set //  flashw_timernofg-0x0000000c flashes until the front of the window displays //flashw_tray------0x00000002 The taskbar button of the flashing window

return value:
The return value represents the active state of the window before the FlashWindowEx function is called, and if the specified window is active before the function is called, a value other than 0 is returned, otherwise 0 is returned.

Examples that are called in C #:

[DllImport ("User32.dll", CharSet = CharSet.Unicode, EntryPoint ="FlashWindowEx")]Private Static extern voidFlashWindowEx (refflashwinfo pwfi); Public structflashwinfo{ PublicUInt32 cbsize;//the byte size of the structure     PublicINTPTR hwnd;//The handle to the window to blink, which can be open or minimized     PublicUInt32 DwFlags;//Flashing State     PublicUInt32 Ucount;//number of flashing windows     PublicUInt32 dwtimeout;//The frequency, in milliseconds, of the window blink, or the default icon's flicker frequency if the value is 0} Public ConstUInt32 Flashw_tray =2; Public ConstUInt32 Flashw_timernofg = A;Private voidFlashwin () {flashwinfo finfo=NewFlashwinfo (); Finfo.cbsize=Convert.touint32 (marshal.sizeof (finfo)); Finfo.hwnd= This.    Handle; Finfo.dwflags= Flashw_tray |Flashw_timernofg; Finfo.ucount=3;//Uint32.maxvalue;Finfo.dwtimeout = -; FlashWindowEx (reffinfo);}
View Code

The above example will blink if you call Flashwin ().

Reprinted from: Http://www.hejingzong.cn/blog/viewBlog_59.aspx

C # WinForm implement taskbar program icon Blink

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.