VB .NET 如何实现窗体标题栏的闪烁

NewScar 2017-11-12 12:07:23
设计目标:实现在窗体最小化时,标题栏闪烁,类似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
...全文
456 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
NewScar 2017-11-20
  • 打赏
  • 举报
回复
已经解决! 原来在VB .Net中Integer类型的是32位,Long类型是64位的,而窗口句柄是32位的。所以窗口句柄必须声明为: Public hwnd As Integer 即可!
rmini 2017-11-20
  • 打赏
  • 举报
回复
不知道,继续关注
秋天之落叶 2017-11-19
  • 打赏
  • 举报
回复
哈哈,晕了,走错论坛了,发的是delphi的,
秋天之落叶 2017-11-19
  • 打赏
  • 举报
回复
效果

秋天之落叶 2017-11-19
  • 打赏
  • 举报
回复
需要那么复杂吗?我一看到一堆代码就头疼: procedure TForm1.Button1Click(Sender: TObject); begin Form1.BringToFront; Timer1.Interval := GetCaretBlinkTime; Timer1.Enabled := not Timer1.Enabled; end; procedure TForm1.Timer1Timer(Sender: TObject); begin FlashWindow(Form1.Handle, true); end; XE10.2下测试通过
  • 打赏
  • 举报
回复
添加一个timer控件,然后启动timer控件,设置属性,在后台设置buttonbackcolor就ok了
NewScar 2017-11-13
  • 打赏
  • 举报
回复
Flashwindow一样无效……
threenewbee 2017-11-12
  • 打赏
  • 举报
回复
ByRef formToFlash As Form 这个参数很奇怪,应该传Handle吧
zj_zwl 2017-11-12
  • 打赏
  • 举报
回复
用FlashWindow试试

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧