vb.net关于sendmessage函数使用WM_gettext的声明方法
以下是论坛某个兄弟给的代码,讲如何使用sendmessage发送wm_gettext消息的。经验证代码无误。
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer,ByVal wParam As Integer,ByVal lParam As System.Text.StringBuilder) As Integer
Private Const WM_GETTEXTLENGTH As Integer = &HE
Private Const WM_GETTEXT As Integer = &HD
Sub GetText()
' 查询Eidt中文本长度
Dim textLength As Integer = SendMessage(hdl, WM_GETTEXTLENGTH, 0, Nothing)
textLength = textLength + 1
' 创建字符串缓冲区
Dim build As New System.Text.StringBuilder(textLength)
' 查询Edit中文本
SendMessage(hdl, WM_GETTEXT, textLength, build)
' 显示
MsgBox(build.ToString)
End Sub
我的问题是:我程序中还用到了另外一个声明方法Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32,重点在第四个参数上,应用于SendMessage 窗口句柄, WM_CLOSE, 0, 0 ,但是这两种使用方法不能共存,请问如何处理? vb.net sendmessage Wm_gettext
[解决办法]
这两个本来 就不能共存的一个是unicode版,一个是ansi版
[解决办法]
Public Declare Function SendMessage2 Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
就是了
红色部分可以随便写,叫HelloWorld也可以。