VB一短问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 18:00:47
我想做个监控记录器
控件list1
一旦某某个游戏运行了
他会在list1显示游戏运行了
如果退出,就是显示游戏未运行,而且数据要保留(比如游戏运行了,然后退出时会在下面增加一个游戏未运行

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Private Sub Timer1_Timer()
Dim hwnd As Long ' 储存 FindWindow 函数返回的句柄
hwnd = FindWindow(vbNullString, "地下城与勇士") ' 取得进程标识符
'只要把Windows Media Player换成游戏的名称就可了!
If hwnd = 0 Then
Text1.Text = "游戏未运行"
Else
Text1.Text = "游戏已运行"
End If
End Sub

大家帮我改下他咯

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Private Sub Timer1_Timer()
Dim hwnd As Long ' 储存 FindWindow 函数返回的句柄
hwnd = FindWindow(vbNullString, "地下城与勇士") ' 取得进程标识符
'只要把Windows Media Player换成游戏的名称就可了!
If hwnd = 0 Then
list1.additem "游戏未运行"
Else
list1.additem "游戏已运行"
End If
End Sub