In almost all messengers when your IM window is minimized to the taskbar, IM taskbar item changes color or gets brighter when you have a new message. I've been looking for any help on how to do this using .NET Winforms or WPF
Any code samples?
=====================================================================
EDIT: 开发者_如何学编程I used FlashWindow for my WPF window.
Ref: http://www.aeoth.net/blog/2007/04/27/flashing-the-window-in-wpf-c-2/
You'll want to use the FlashWindowEx function. Basically, get a handle to the window, create a FLASHWINFO structure with the handle and how you want the window to flash (continuously, until it's opened, etc), and pass it into FlashWindowEx.
edit: Here's an example of how to do it in C#.
I was still confused how to make it just highlight the taskbar item and not flash. Here's the code that ended up working for me (I feel pretty silly for missing setting count to 1, hopefully this will save someone else time).
Public Structure FLASHWINFO
Public cbSize As UInt32
Public hwnd As IntPtr
Public dwFlags As UInt32
Public uCount As UInt32
Public dwTimeout As UInt32
End Structure
Private Declare Function FlashWindowEx Lib "user32.dll" (ByRef pfwi As FLASHWINFO) As Boolean
Private Const FLASHW_STOP As UInt32 = 0
Private Const FLASHW_CAPTION As UInt32 = 1
Private Const FLASHW_TRAY As UInt32 = 2
Private Const FLASHW_ALL As UInt32 = 3
Private Const FLASHW_TIMER As UInt32 = 4
Private Const FLASHW_TIMERNOFG As UInt32 = 12
Public Shared Sub Flash(ByRef thisForm As Form)
Dim flash As New FLASHWINFO With {
.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(flash),
.hwnd = thisForm.Handle,
.dwFlags = FLASHW_TRAY Or FLASHW_TIMERNOFG,
.uCount = 1}
'Leaving out .dwCount seems to work just fine for me, the uCount above keeps it from flashing
FlashWindowEx(flash)
End Sub
精彩评论