荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: Peter (小飞侠), 信区: Program
标 题: 闪动标题栏
发信站: BBS 荔园晨风站 (Tue Jan 26 22:56:43 1999), 转信
闪动标题栏
微软公司供稿
摘要
在你的应用程序中,你可能会希望将应用程序的标
题栏进行闪动,以提醒用户进行某种操作,本文介绍了
如何使一个窗口的标题栏进行闪动。
闪动标题栏
闪动一个窗口的标题栏意味着改变它的标题栏的外观,
例如它从活动变为不活动,或是从不活动变为活动等等。
只要你能在Visual Basic中得到窗口的句柄,你就可以
使用Windows 应用程序编程接口(API)函数来使该窗
口的标题栏进行闪动。函数FlashWindows可以被用使一
个特定的窗口闪动一次。要使用该函数,需要将如下的
声明语句包含在你的窗体的通用声明部分中:
#If Win32 Then
Declare Function FlashWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal bInvert As Long) As Long
#Else
Declare Function FlashWindow Lib "User" ( _
ByVal hwnd As Integer, _
ByVal bInvert As Integer) As Integer
#End If
该函数需要2个参数,第一个参数是要闪动标题栏的窗
口的句柄,第二个参数用于指定是设置窗口的闪动状
态,还是恢复其原始状态。如果该bInvert参数非0,
则表明窗口的标题栏被闪动,如果该参数为0,则表明
窗口的标题栏被恢复为原始状态。
该函数所返回的值用于指定调用该函数前窗口的状态,
如果该返回值非0,则表明窗口在调用该函数之前是活
动的,否则,如果返回值为0,则表明调用函数前窗口
是非活动的。
当使用该FlashWindow函数时,一个较好的方法是将标
题栏闪动的频率设置为同脱字符(也即闪动的光标)
相同,脱字符的闪动频率可以通过调用函数
GetCaretBlinkTime来获得。要使用该函数,需要将如
下的声明语句包含在你的窗体的通用声明部分中:
#If Win32 Then
Declare Function GetCaretBlinkTime Lib "user32" () As Long
#Else
Declare Function GetCaretBlinkTime Lib "User" () As Integer
#End If
该函数返回用毫秒值表示的时间。
样例程序
1. 在Visual Basic中开始一个新的工程,采用缺
省的方法建立Form1。
2. 在Form1上添加一个定时器控件,采用缺省的
方法建立Timer1。
3. 将如下的代码添加到Form1的Form_GotFocus事件中:
Private Sub Form_GotFocus()
Timer1.Enabled = False
End Sub
4. 将如下的代码添加到Form1的Form_Load事件中:
Private Sub Form_Load()
Timer1.Interval = GetCaretBlinkTime()
Form2.Show
End Sub
5. 将如下的代码添加到Timer1的Timer1_Timer事件中:
Private Sub Timer1_Timer()
Success = FlashWindow(Form1.hwnd, 1)
End Sub
6. 添加第二个窗体,采用缺省的方法建立Form2。
7. 将如下的代码添加到Form2的单击事件中:
Private Sub Form_Click()
Form1.Timer1.Enabled = True
End Sub
8. 添加一个新的模块,采用缺省的方法建立
Module1.Bas。将如下的代码添加到该模块的通用声明部分中:
#If Win32 Then
Declare Function FlashWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal bInvert As Long) As Long
Declare Function GetCaretBlinkTime Lib "user32" () As Long
Dim Success As Long
#Else
Declare Function FlashWindow Lib "User" ( _
ByVal hwnd As Integer, _
ByVal bInvert As Integer) As Integer
Declare Function GetCaretBlinkTime Lib "User" () As Integer
Dim Success As Integer
#End If
通过单击F5键来运行该样例程序,单击Form2窗体,这
时Form1窗体将处于非活动方式,其标题栏将会不断闪烁。
单击Form1使它它变为活动方式,则窗体的标题栏将不再闪
烁。如图1所示。
图1
--
※ 来源:.BBS 荔园晨风站 bbs.szu.edu.cn.[FROM: 192.168.1.3]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店