SendMessage+WM_GETTEXT的疑惑,请教大虾~~~~~~~~~~~~~~~~
需要取得另1程序上一个Edit控件上的内容,Edit的句柄 HWND 已取得,
但是Edit控件上的内容的长度可能很长,也可能很短
下面是从网上COPY来的一段代码,有些不明
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_GETTEXT = &HD
Private Sub Command1_Click()
Dim s As String
s = String(255, Chr(0)) '对于长度不确定,可能几千字符的,这里咋办?
Call SendMessage(HWND, WM_GETTEXT, 255, s)
s = Left(s, InStr(1, s, Chr(0)) - 1) '这里为什么要再这样处理一下?不这样处理,好像也可获得同样结果
Text1 = s
End Sub
[解决办法]
不处理会多出很多Chr(0)
[解决办法]
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_GETTEXT = &HD
Private Sub Command1_Click()
Dim s As String
s = String(25555, Chr(0)) '对于长度不确定,可能几千字符的,这里咋办?
Call SendMessage(Text1.hwnd, WM_GETTEXT, 25555, s)
s = Left(s, InStr(1, s, Chr(0)) - 1) '这里为什么要再这样处理一下?不这样处理,好像也可获得同样结果
Text2 = s
End Sub
Private Sub Form_Load()
For i = 0 To 1000
s = s & i
Next
Text1.Text = s
End Sub
[解决办法]
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
【操作系统】
Win9X:Yes
WinNT:Yes
【说明】
调用一个窗口的窗口函数,将一条消息发给那个窗口。除非消息处理完毕,否则该函数不会返回。SendMessageBynum,
SendMessageByString是该函数的“类型安全”声明形式
【返回值】
Long,由具体的消息决定
【其它】
【参数表】
hwnd ----------- Long,要接收消息的那个窗口的句柄
wMsg ----------- Long,消息的标识符
wParam --------- Long,具体取决于消息
lParam --------- Any,具体取决于消息
Const WM_GETTEXT = &HD
取得文本消息