下面是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 - メモ帳")
FindWindow查找窗口句柄
两个参数,第一个是类名,第二个是窗口的标题,返回值是窗口句柄
不清楚的情况下,两个参数中间的一个可以设成0
- subHwnd = FindWindowEx(myhwnd, 0, "Edit", 0)
- SendMessage(subHwnd, &H302, 0, 0)
总之消息不是普通的字符串, 而是包括鼠标,键盘等一切消息 这里&H302消息为粘贴到指定句柄
转载于:https://blog.51cto.com/haiblue/883622