Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Sub Timer1_Timer()
Dim a As Long
a = GetForegroundWindow()
Text1 = CStr(a)
Text2 = Me.hwnd
If a <> Me.hwnd Then SetForegroundWindow (Me.hwnd)
End Sub
GetForegroundWindow
VB声明
Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
说明
获得前台窗口的句柄。这里的“前台窗口”是指前台应用程序的活动窗口
返回值
Long,前台窗口的句柄
注解
windows nt支持多个桌面,它们相互间是独立的。每个桌面都有自己的前台窗口
SetForegroundWindow
VB声明
Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
说明
将窗口设为系统的前台窗口。这个函数可用于改变用户目前正在操作的应用程序
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
hwnd Long,带到前台的窗口
注解
不应随便使用它,因为一旦程序突然从后台进入前台,可能会使用户产生迷惑
VB声明
Declare Function IsWindowEnabled Lib "user32" Alias "IsWindowEnabled" (ByVal hwnd As Long) As Long
说明
判断窗口是否处于活动状态(在vb里使用:针对vb窗体和控件,请用enabled属性)
返回值
Long,非零表示成功,零表示失败
参数表
参数 类型及说明
hwnd Long,待检测窗口的句柄
举个例子:
Public fflag As Boolean
Private Sub MDIForm_Load()
fflag = False
End Sub
Private Sub numDept_Click()
If fflag = True Then
MsgBox "打开新窗口前,请关闭其他窗口", vbOKOnly, "警告"
Exit Sub
End If
Load Dept_frm
numDept.Enabled = False
End Sub
Private Sub numEmp_Click()
If fflag = True Then
MsgBox "打开新窗口前,请关闭其他窗口", vbOKOnly, "警告"
Exit Sub
End If
Load Employee_frm
numEmp.Enabled = False
End Sub
Private Sub numExit_Click()
Unload Me
End Sub
Private Sub numSalary_Click()
If fflag = True Then
MsgBox "打开新窗口前,请关闭其他窗口", vbOKOnly, "警告"
Exit Sub
End If
Load Salary_frm
numSalary.Enabled = False
End Sub
易如反掌的问题:
在form_activete form_deactivete 之中监视一下
dim bActive as boolen
private sub form activate()
bactive = true
end sub
provate sub form deactivate()
bavtive = false
end sub