设计目标:实现在窗体最小化时,标题栏闪烁,类似WeChat有新消息时的状态。
设计思路:打算利用API中的FlashWindowEx方法来现实。
问题:无法实现,代码如下。恳请各位不吝赐教!
Private Declare Auto Function FlashWindowEx Lib "User32" (ByRef fwInfo As FLASHWINFO) As Boolean
Public Enum FlashWindowFlags As UInteger
FLASHW_STOP = 0
FLASHW_CAPTION = 1
FLASHW_TRAY = 2
FLASHW_ALL = 3
FLASHW_TIMER = 4
FLASHW_TIMERNOFG = 12
End Enum
Public Structure FLASHWINFO
Public cbSize As Long
Public hwnd As Long
Public dwFlags As FlashWindowFlags
Public uCount As Long
Public dwTimeout As Long
End Structure
Public Function FlashWindow(ByRef formToFlash As Form) As Boolean
Return FlashWindow(formToFlash, True, True, 5)
End Function
Public Function FlashWindow(ByRef formToFlash As Form, ByVal FlashTitleBar As Boolean, ByVal FlashTray As Boolean) As Boolean
Return FlashWindow(formToFlash, FlashTitleBar, FlashTray, 5)
End Function
Public Function FlashWindow(ByRef formToFlash As Form, ByVal FlashCount As Integer) As Boolean
Return FlashWindow(formToFlash, True, True, FlashCount)
End Function
Public Function FlashWindow(ByRef formToFlash As Form, ByVal FlashTitleBar As Boolean, ByVal FlashTray As Boolean, ByVal FlashCount As Integer) As Boolean
If formToFlash Is Nothing Then Return False
If formToFlash.IsDisposed Then Return False
If formToFlash.Handle = 0 Then Return False
Try
Dim fwi As New FLASHWINFO
With fwi
.hwnd = formToFlash.Handle
If FlashTitleBar Then .dwFlags = .dwFlags Or FlashWindowFlags.FLASHW_CAPTION
If FlashTray Then .dwFlags = .dwFlags Or FlashWindowFlags.FLASHW_TRAY
.uCount = FlashCount
If FlashCount = 0 Then .dwFlags = .dwFlags Or FlashWindowFlags.FLASHW_TIMERNOFG
.dwTimeout = 0
.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(fwi)
End With
Return FlashWindowEx(fwi)
Catch
Return False
End Try
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
FlashWindow(Me)
End Sub