C # Highlight the taskbar (the task is stopped after 3 seconds of flashing and remains highlighted)
Zookeeper
Today, I use C # as a communication software similar to QQ. Sometimes I don't notice the message, so I want to flash the taskbar after receiving the message, and finally highlight the orange color, it's like sending messages via QQ. After searching and querying the API repeatedly, you need to use this function to find that the taskbar is flashing and staying:
Public static extern bool flash1_wex (ref FLASHWINFO pwfi );
The key code for implementation is as follows:
[DllImport ("user32.dll")]
Public static extern bool flash1_wex (ref FLASHWINFO pwfi );
Public enum falshType: uint
{
FLASHW_STOP = 0, // stop flashing
FALSHW_CAPTION = 1, // only flashes the title
FLASHW_TRAY = 2, // only flashes the taskbar
FLASHW_ALL = 3, // The title and taskbar flash simultaneously
FLASHW_PARAM1 = 4,
FLASHW_PARAM2 = 12,
FLASHW_TIMER = FLASHW_TRAY | FLASHW_PARAM1, // flashes the taskbar unconditionally until the sending Stop sign or window is activated. If not activated, highlight it when it is stopped.
FLASHW_TIMERNOFG = FLASHW_TRAY | FLASHW_PARAM2 // flash the taskbar when it is not activated until the stop sending sign or the form is activated. Highlight it after it is stopped.
}
Public static bool flashTaskBar (IntPtr hWnd, falshType type)
{
FLASHWINFO fInfo = new FLASHWINFO ();
FInfo. cbSize = Convert. ToUInt32 (Marshal. SizeOf (fInfo ));
FInfo. hwnd = hWnd; // handle of the window to flash. The window can be opened or minimized.
FInfo. dwFlags = (uint) type; // flashing type
FInfo. uCount = UInt32.MaxValue; // Number of blinking windows
FInfo. dwTimeout = 0; // The frequency of window blinking, in milliseconds. If this value is 0, it is the flashing frequency of the default icon.
Return flashmediawex (ref fInfo );
}
The following call: if the task is not activated, the taskbar will flash until the sending Stop sign or the form is activated. After the task is highlighted and activated, it will be normal. This is the same as QQ, the activation window is a stop highlight event:
FlashTaskBar (this. Handle, falshType. FLASHW_TIMERNOFG );
However, QQ does not flash when processing the activation status in the session window, so that sometimes the messages sent by the other party are not noticed. Therefore, if you want to activate the form or not, the taskbar will flash when there is a new message until the text is entered by the user. This can be called as follows:
FlashTaskBar (this. Handle, falshType. FLASHW_TIMER );
When a user inputs an event, the event is triggered. You can add the following calls to the event processing function:
The following call: stop flashing. If the window is not activated after the stop, it is highlighted. If the window is active, it is stopped and not highlighted.
FlashTaskBar (this. Handle, falshType. FLASHW_STOP );
In addition, you have not found a way to keep the active window highlighted. It seems that the active window will definitely be unhighlighted.