下面是VB.net的代码 和VB的区别在于数据类型 vb中long是4byte,vb.net中间Integer是4byte 用的时候写法要互相转换一下 不放心的话可以都写成Int32
- Public Class Form1
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
- 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 Integer
- Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim myhwnd As Integer
- Dim subHwnd As Integer
- myhwnd = FindWindow("Notepad", "test.txt - メモ帳")
- subHwnd = FindWindowEx(myhwnd, 0, "Edit", 0)
- SendMessage(subHwnd, &H302, 0, 0)
- 'MsgBox(subHwnd)
- End Sub
- End Class
- myhwnd = FindWindow("Notepad", "test.txt - メモ帳")
- subHwnd = FindWindowEx(myhwnd, 0, "Edit", 0)
FindWindowEx查找子窗口句柄 4个参数, 第一个是父窗口句柄, 第二个是子窗口次序(父窗口下第几个子窗口), 第三个是子窗口类型, 第四个是子窗口名字
- SendMessage(subHwnd, &H302, 0, 0)
SendMessage将指定的消息发送到一个或多个窗口 此函数太过于强大,不多做解释
总之消息不是普通的字符串, 而是包括鼠标,键盘等一切消息 这里&H302消息为粘贴到指定句柄