2个回答
展开全部
在窗口界面区内加入控件text1,text2及command1,在窗口代码区复制下面代码,然后运行,在text1用来输入记事本编辑区的句柄,text2用来输入向它发送的文本,按command1按钮,文本就成功地被发送出去了。
Option Explicit
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 SendMessageByString Lib "user32" Alias _
"SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam _
As Long, ByVal lParam As String) As Long
Private Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const EM_SETSEL = &HB1
Private Const EM_LINELENGTH = &HC1
Private Const EM_REPLACESEL = &HC2
Private Sub Command1_Click()
Dim K As Long, Hwd As Long, SendString As String
Hwd = Text1.Text
SendString = Text2.Text
K = SendMessage(Hwd, EM_LINELENGTH, 1, 0) '取得文本宽度
SendMessageByNum Hwd, EM_SETSEL, 0, K '选中文本
SendMessageByString Hwd, EM_REPLACESEL, 1, SendString '传递文本
End Sub
Option Explicit
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 SendMessageByString Lib "user32" Alias _
"SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam _
As Long, ByVal lParam As String) As Long
Private Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const EM_SETSEL = &HB1
Private Const EM_LINELENGTH = &HC1
Private Const EM_REPLACESEL = &HC2
Private Sub Command1_Click()
Dim K As Long, Hwd As Long, SendString As String
Hwd = Text1.Text
SendString = Text2.Text
K = SendMessage(Hwd, EM_LINELENGTH, 1, 0) '取得文本宽度
SendMessageByNum Hwd, EM_SETSEL, 0, K '选中文本
SendMessageByString Hwd, EM_REPLACESEL, 1, SendString '传递文本
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询