vb中想用函数sendmessage向记事本发送消息!该如何写代码...
1个回答
2013-10-24
展开全部
'新烂晌建一个abc.txt文件并打开,测试正常Option Explicit
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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim s As String, myhwnd As Long
s = Text1
myhwnd = FindWindow(vbNullString, "abc.txt - 记事本")
myhwnd = FindWindowEx(myhwnd, 0&, "Edit", vbNullString) '控件名用spy++查饥宴锋看,这里是Edit,特定的软件祥郑控件名都是固定的
If myhwnd = 0 Then
MsgBox "!!"
Exit Sub
End If
SendMessage myhwnd, WM_SETTEXT, 0, ByVal s
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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim s As String, myhwnd As Long
s = Text1
myhwnd = FindWindow(vbNullString, "abc.txt - 记事本")
myhwnd = FindWindowEx(myhwnd, 0&, "Edit", vbNullString) '控件名用spy++查饥宴锋看,这里是Edit,特定的软件祥郑控件名都是固定的
If myhwnd = 0 Then
MsgBox "!!"
Exit Sub
End If
SendMessage myhwnd, WM_SETTEXT, 0, ByVal s
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询