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 Const EM_GETLINE = &HC4
Private Const EM_CHARFROMPOS = &HD7
Option Explicit
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim pos As Long, lc As Long
Dim Line As Integer, CharPos As Integer
Dim str1 As String * 250
Dim str2 As String
Dim str3 As String
x = x / Screen.TwipsPerPixelX
y = y / Screen.TwipsPerPixelY
pos = x + y * 65536
lc = SendMessage(Text1.hwnd, EM_CHARFROMPOS, 0, ByVal pos)
Line = lc \ 65536 '这里不得到的是行号?
CharPos = lc Mod 65536
MsgBox "第几行 = " & Line & vbCrLf & "第几个字符= " & CharPos
' 根据MSDN对EM-GETLINE的说明
' EM_GETLINE
'wParam = (WPARAM) line; // line number to retrieve 找到的行号
'lParam = (LPARAM) (LPCSTR) lpch; // address of buffer for line行的内存地址
SendMessage Text1.hwnd, EM_GETLINE, lc, ByVal str1
str3 = StrConv(str1, vbUnicode)
str2 = Left(str3, InStr(1, str3, Chr(0) - 1))
MsgBox str2End Sub '我知道白把str1(230)这样的行,但在这样为什么就不行?lc得到了行号,我直接用不就行了吗?
Private Const EM_GETLINE = &HC4
Private Const EM_CHARFROMPOS = &HD7
Option Explicit
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim pos As Long, lc As Long
Dim Line As Integer, CharPos As Integer
Dim str1 As String * 250
Dim str2 As String
Dim str3 As String
x = x / Screen.TwipsPerPixelX
y = y / Screen.TwipsPerPixelY
pos = x + y * 65536
lc = SendMessage(Text1.hwnd, EM_CHARFROMPOS, 0, ByVal pos)
Line = lc \ 65536 '这里不得到的是行号?
CharPos = lc Mod 65536
MsgBox "第几行 = " & Line & vbCrLf & "第几个字符= " & CharPos
' 根据MSDN对EM-GETLINE的说明
' EM_GETLINE
'wParam = (WPARAM) line; // line number to retrieve 找到的行号
'lParam = (LPARAM) (LPCSTR) lpch; // address of buffer for line行的内存地址
SendMessage Text1.hwnd, EM_GETLINE, lc, ByVal str1
str3 = StrConv(str1, vbUnicode)
str2 = Left(str3, InStr(1, str3, Chr(0) - 1))
MsgBox str2End Sub '我知道白把str1(230)这样的行,但在这样为什么就不行?lc得到了行号,我直接用不就行了吗?
解决方案 »
- [求助]VB实现的ActiveX导致IE6崩溃的问题
- 请教一个很简单问题
- 如何使已经创建好的VPN连接进行连接(内附创建VPN连接代码)
- 谁有VB程序能用的图标?为什么我下载的ico都不能用,提示:无效图片。
- 很简单的问题,进来看一下。
- 写一个控件时,设置Font属性出错,不解
- 水晶报表大全
- VB6利用SoapToolkit30开发客户端出错:实时错误:-2147024809(80070057)
- 关于MSComm控件的CommEvent中的ComEvRing
- 打印机设置的问题
- 菜鸟提问:如何将一个文本框中的某几个字母更改为另外几个字母,然后输出到另一个文本框中?
- 急,请问哪儿有英文版的VB6.0下载??
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 Const EM_GETLINE = &HC4Private Function GetLine(Text1 As TextBox, ByVal ntx As Long) As String
Dim str1(255) As Byte '如果您的字串 > 255 byte请自行增加该Byte Array
Dim str2 As String, i As Long
str1(0) = 255 '字串的前两个Byte存该字串的最大长度
str1(0) = 255
i = SendMessage(Text1.hwnd, EM_GETLINE, ntx, str1(0))
If i = 0 Then
GetLine = ""
Else
str2 = StrConv(str1, vbUnicode)
GetLine = Left(str2, InStr(1, str2, Chr(0)) - 1)
End If
End FunctionPrivate Sub Command1_Click()
Dim str1 As String
str1 = GetLine(Text1, 2) '取得第二行的字串,以0为基底
Debug.Print str1
End SubPrivate Sub Form_Load()
Text1.Text = "中华人民共和国0" & vbCrLf & "中华人民共和国1" & vbCrLf & "中华人民共和国2" & vbCrLf & "中华人民共和国3"
End Sub