vb如何获取当前活动窗口的标题名称

来源:百度知道 编辑:UC知道 时间:2024/05/17 01:15:58

'添加窗体Form1,卷标Label1,定时器Timer1,然后添加如下代码:
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Dim hWnd1 As Long

Private Sub Form_Load()
    Label1.AutoSize = True
    Timer1.Interval = 500
End Sub

Private Sub Timer1_Timer()
    hWnd1 = GetForegroundWind