会员: 密码:  免费注册 | 忘记密码 | 会员登录 网页功能: 加入收藏 设为首页 网站搜索  
 安全技术技术文档
  · 安全配制
  · 工具介绍
  · 黑客教学
  · 防火墙
  · 漏洞分析
  · 破解专题
  · 黑客编程
  · 入侵检测
 安全技术论坛
  · 安全配制
  · 工具介绍
  · 防火墙
  · 黑客入侵
  · 漏洞检测
  · 破解方法
  · 杀毒专区
 安全技术工具下载
  · 扫描工具
  · 攻击程序
  · 后门木马
  · 拒绝服务
  · 口令破解
  · 代理程序
  · 防火墙
  · 加密解密
  · 入侵检测
  · 攻防演示
技术文档 > VB文档 > 窗体界面
如何实现在TextBox中如何得知光标所在位置
发表日期:2003-07-02 00:00:00作者: 出处:  

'在form中放一个textBox两个label

Const EM_GETSEL = &HB0

Const EM_LINEFROMCHAR = &HC9

Const EM_LINEINDEX = &HBB

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

Public Sub GetCaretPos(ByVal hwnd5 As Long, LineNo As Long, ColNo As Long)

Dim i As Long, j As Long

Dim lParam As Long, wParam As Long

Dim k As Long

i = SendMessage(hwnd5, EM_GETSEL, wParam, lParam)

j = i / 2 ^ 16 '取得目前Caret所在前面有多少个byte

LineNo = SendMessage(hwnd5, EM_LINEFROMCHAR, j, 0) '取得前面有多少行

LineNo = LineNo + 1

k = SendMessage(hwnd5, EM_LINEINDEX, -1, 0)

'取得目前caret所在行前面有多少个byte

ColNo = j - k + 1

End Sub

Private Sub Form_Load()

Dim LineNo As Long, ColNo As Long

Call GetCaretPos(Text1.hwnd, LineNo, ColNo)

Label1.Caption = LineNo

Label2.Caption = ColNo

End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)

Dim LineNo As Long, ColNo As Long

Call GetCaretPos(Text1.hwnd, LineNo, ColNo)

Label1.Caption = LineNo

Label2.Caption = ColNo

End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim LineNo As Long, ColNo As Long

Call GetCaretPos(Text1.hwnd, LineNo, ColNo)

Label1.Caption = LineNo

Label2.Caption = ColNo

End Sub

返回顶部】 【打印本页】 【关闭窗口

关于我们 / 给我留言 / 版权举报 / 意见建议 / 网站编程QQ群   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net 加载时间 0.00139