使用PostMessage加SendKeys: 打开一个Notepad的窗口,随便输入一些字符 Form中的代码:Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongConst SW_SHOWNORMAL = 1 Const WM_CLOSE = &H10Private Sub Form_Load()
Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
Ret = "Untitled - Notepad" WinWnd = FindWindow(vbNullString, Ret) If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
打开一个Notepad的窗口,随便输入一些字符
Form中的代码:Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongConst SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10Private Sub Form_Load()
Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
Ret = "Untitled - Notepad"
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
ShowWindow WinWnd, SW_SHOWNORMAL
PostMessage WinWnd, WM_CLOSE, 0&, 0&
SendKeys "{TAB}"
SendKeys "{ENTER}"
End Sub
处于即或状态?
如果某人正在玩,可以吗?(自动给他关闭)
to 诺亚方舟:
可是我的SETDKEYs 执行不了呀.