vba通过findwindow获取窗口句柄后并判断是否为活动窗口

2017-09-17 08:00:00
zstmtony
原创
1175

vba通过findwindow获取窗口句柄后并判断是否为活动窗口


'定义Findwindow windows API 函数
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long  '定义GetForegroundWindows API 获取最前面窗体 Private Declare Function GetForegroundWindow Lib "user32" () As Long
 '可以通过查看前景窗口是否为指定窗口判断
 hwd1 = FindWindow("#32770", "QQ用户登录")
  
   '获得指定窗口句柄 hwd2 = GetForegroundWindow

'获得前景窗口句柄 If hwd1 = hwd2 Then MsgBox "指定窗口为活动状态!"
'判断是否相同
分享