If Dir(\"alive\") <> \"\" And Dir(\"ideal\") <> \" Then Print \"strive\" End If
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Private Const WM_KEYDOWN = &H100
Private Sub Command1_Click()
Timer1.Interval = 500
End Sub
Private Sub Timer1_Timer()
Dim findhwnd As Long
findhwnd = FindWindow(vbNullString, "Crazy Arcade")
If findhwnd = 0 Then
Me.Caption = "未运行"
Else
Me.Caption = "已运行"
SendMessage findhwnd, WM_KEYDOWN, 65, 0&
End If
End Sub
我刚测试过这段代码,没有问题的 要注意 有的时候应用程序窗口的标题并非是其真正的Caption,例如千千静听.这个时候我们需要借助其它工具先取得它的Caption,给你介绍个工具Spy++,你说的那个跑跑堂我没玩过,但是我们只要能取得它的窗口Caption,我们一样可以向它发送任意消息
另外,我要说明一点 取得窗口句柄的方法还有很多 例如我们可以遍历所有的窗口,我们可以取得当前活动的窗口只要我们调用不同的API函数就可以了 Findwindow只是一种途径
[此贴子已经被作者于2007-4-21 10:00:50编辑过]
可是信息真的发不出去呀。我又拿这个来做了实验
Private Sub Command1_Click()
Timer1.Interval = 500
End Sub
Private Sub Timer1_Timer()
Dim hwnd As Long '
hwnd = FindWindow(vbNullString, "Login") 'Crazy Arcade
If hwnd = 0 Then
Label1.Caption = "未运行"
Else
Label1.Caption = "已运行"
SendMessage findhwnd, WM_KEYDOWN, 65, 1&
End If
End Sub