用VB激活窗口并模拟键盘输入
用VB程序激活一个最小化窗口,激活后在后台运行并模拟键盘输入。例如:打开记事本,把它最小化,程序运行时在“记事本”里放入几个字符。要有注释的程序代码!运行后别再自己窗口里...
用VB程序激活一个最小化窗口,激活后在后台运行并模拟键盘输入。
例如:打开记事本,把它最小化,程序运行时在“记事本”里放入几个字符。
要有注释的程序代码!运行后别再自己窗口里键入字符! 展开
例如:打开记事本,把它最小化,程序运行时在“记事本”里放入几个字符。
要有注释的程序代码!运行后别再自己窗口里键入字符! 展开
1个回答
展开全部
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim hwnd As Long, Thwnd As Long
Shell "notepad.exe", 2 '打开一个记事本,将它最小化
hwnd = FindWindow("Notepad", "无标题 - 记事本") '得到记事本句柄
Thwnd = FindWindowEx(hwnd, 0, "Edit", vbNullString) '得到记事本句柄(就是我们写字的那里)
SendMessage Thwnd, WM_SETTEXT, 0, ByVal "好了,快给我分" '向记事本写入文字
End Sub
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim hwnd As Long, Thwnd As Long
Shell "notepad.exe", 2 '打开一个记事本,将它最小化
hwnd = FindWindow("Notepad", "无标题 - 记事本") '得到记事本句柄
Thwnd = FindWindowEx(hwnd, 0, "Edit", vbNullString) '得到记事本句柄(就是我们写字的那里)
SendMessage Thwnd, WM_SETTEXT, 0, ByVal "好了,快给我分" '向记事本写入文字
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询