VB中,怎么向已知句柄的窗口发送文本

我已经知道了记事本编辑区的句柄,怎么向它发送文本呢,请各位大虾帮忙... 我已经知道了记事本编辑区的句柄,怎么向它发送文本呢,请各位大虾帮忙 展开
 我来答
ljl88900
2009-09-26 · TA获得超过2661个赞
知道大有可为答主
回答量:2197
采纳率:100%
帮助的人:2642万
展开全部
在窗口界面区内加入控件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
hawking_xu
2009-09-26 · TA获得超过215个赞
知道小有建树答主
回答量:211
采纳率:0%
帮助的人:156万
展开全部
记事本编辑区的句柄?
记事本是纯文本编辑器
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式