7,765
社区成员
发帖
与我相关
我的任务
分享
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 = GetForegroundWindow() '得到活动窗口的句柄
Label1.Caption = getCaption(hWnd1)
Text1.Text = getCaption(hWnd1)
End Sub
'根据窗口句柄得到该窗口的标题
Function getCaption(hWnd As Long)
Dim hWndlength As Long, hWndTitle As String, A As Long
hWndlength = GetWindowTextLength(hWnd)
hWndTitle = String$(hWndlength, 0)
A = GetWindowText(hWnd, hWndTitle, (hWndlength + 1))
getCaption = hWndTitle
End Function
Private Sub Command1_Click()
End
End Sub
Option Explicit
Dim hWnd1 As Long
Dim eCategory As Long
Dim sSpicalCaption As String
Private Sub Timer1_Timer()
Dim a() As String
hWnd1 = GetForegroundWindow()
Label1.Caption = getCaption(hWnd1)
Text1.Text = Label1.Caption
If Text1.Text Like "*与*对话" Then
a = Split(Left$(Text1.Text, Len(Text1.Text) - 2), "与")
sSpicalCaption = Trim$(a(0)) & Trim$(a(1))
eCategory = 1
Else
sSpicalCaption = vbNullString
Select Case Text1.Text
Case "系统错误"
eCategory = 2
Case "登录"
eCategory = 3
Case Else
eCategory = 4
End Select
End If
End Sub
'需要的俩变量
Dim strOne As String
Dim strAnother As String
Private Sub Timer1_Timer()
hWnd1 = GetForegroundWindow() '得到活动窗口的句柄
Label1.Caption = getCaption(hWnd1)
Text1.Text = getCaption(hWnd1)
If Label1.Caption Like "*与*对话" Then
strOne = Trim(Left(Label1.Caption, InStr(Label1.Caption, "与") - 1))
strAnother = Trim(Mid(Label1.Caption, InStr(Label1.Caption, "与") + 1, InStr(Label1.Caption, "对话") - InStr(Label1.Caption, "与") - 1))
ElseIf Label1.Caption = "系统错误" Then
ElseIf Label1.Caption = "登陆" Then
Else '非以上三种
End If
End Sub
If Text1.Text Like "*与*对话" Then
a = Split(Left$(Text1.Text, Len(Text1.Text) - 2), "与")
sSpicalCaption = Trim$(a(0)) & Trim$(a(1))
eCategory = 1
Else