找回密码
 立即注册
搜索
查看: 388|回复: 4

一个编程的问题

[复制链接]

64

主题

76

回帖

183

积分

海星

积分
183
发表于 2002-5-5 00:19:58 | 显示全部楼层 |阅读模式
VB问题
怎样用鼠标捕捉用MSCHART输出的图表上的点,并显示出点的坐标。可以实现吗?
有谁知道具体步骤吗???

327

主题

3264

回帖

3641

积分

荣誉版主

积分
3641
发表于 2002-5-5 01:10:09 | 显示全部楼层
VB不懂,不会用!不知道怎么解决!
回复

使用道具 举报

发表于 2002-5-5 14:39:21 | 显示全部楼层
没试过,列一个捕捉词的。


先是模块声明:

getword.bas

  1. Public Const EM_CHARFROMPOS = &HD7
  2. Public Const EM_GETLINECOUNT = &HBA
  3. Public Const EM_GETLINE = &HC4
  4. Public Const EM_LINEINDEX = &HBB
  5. Public Const EM_LINELENGTH = &HC1

  6. Declare Sub RtlMoveMemory Lib "KERNEL32" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
  7. Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
复制代码



然后是form1


  1. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.     Dim pos As Long, lc As Long
  3.     Dim Line As Integer, CharPos As Integer
  4.    
  5.     pos = X / Screen.TwipsPerPixelX + Y / Screen.TwipsPerPixelY * 65536
  6.     lc = SendMessage(Text1.hwnd, EM_CHARFROMPOS, 0, ByVal pos)
  7.    
  8.     Line = lc \ 65536
  9.     CharPos = lc Mod 65536
  10.    
  11.     MsgBox "?? = " & GetLine(Text1, Line) & vbCrLf & "单词= " & GetWord(Text1, CharPos)
  12. End Sub

  13. Function GetWord(txt As TextBox, pos As Integer) As String
  14.     Dim bArr() As Byte, pos1 As Integer, pos2 As Integer, i As Integer
  15.    
  16.     bArr = StrConv(txt.Text, vbFromUnicode)
  17.     pos1 = 0: pos2 = UBound(bArr)
  18.    
  19.    
  20.     For i = pos - 1 To 0 Step -1
  21.         If IsDelimiter(bArr(i)) Then
  22.             pos1 = i + 1
  23.             Exit For
  24.         End If
  25.     Next
  26.    
  27.    
  28.     For i = pos To UBound(bArr)
  29.         If IsDelimiter(bArr(i)) Then
  30.             pos2 = i - 1
  31.             Exit For
  32.         End If
  33.     Next
  34.    
  35.     If pos2 > pos1 Then
  36.         ReDim bArr2(pos2 - pos1) As Byte
  37.         For i = pos1 To pos2
  38.             bArr2(i - pos1) = bArr(i)
  39.         Next
  40.    
  41.         GetWord = StrConv(bArr2, vbUnicode)
  42.     Else
  43.         GetWord = ""
  44.     End If
  45. End Function

  46. Function IsDelimiter(ByVal Char As Byte) As Boolean
  47.     Dim S As String
  48.    
  49.     S = Chr(Char)
  50.     IsDelimiter = False
  51.     If S = " " Or S = "," Or S = "." Or S = "?" Or S = vbCr Or S = vbLf Then
  52.         IsDelimiter = True
  53.     End If
  54. End Function

  55. Function GetLine(txt As TextBox, ByVal Line As Integer) As String
  56.     Dim S As String, Length As Integer, pos As Long
  57.    
  58.     GetLine = ""
  59.     pos = SendMessage(txt.hwnd, EM_LINEINDEX, Line, ByVal 0&)
  60.     Length = SendMessage(txt.hwnd, EM_LINELENGTH, pos, ByVal 0&)
  61.     S = String(Length, Chr(0))
  62.     RtlMoveMemory ByVal S, Length, 2
  63.     If SendMessage(Text1.hwnd, EM_GETLINE, Line, ByVal S) > 0 Then
  64.         GetLine = S
  65.     End If
  66. End Function

  67. Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  68.     Dim pos As Long, lc As Long
  69.     Dim Line As Integer, CharPos As Integer
  70.    
  71.     pos = X / Screen.TwipsPerPixelX + Y / Screen.TwipsPerPixelY * 65536
  72.     lc = SendMessage(Text1.hwnd, EM_CHARFROMPOS, 0, ByVal pos)
  73.    
  74.     Line = lc \ 65536
  75.     CharPos = lc Mod 65536
  76.    
  77.     Text1.ToolTipText = GetWord(Text1, CharPos)
  78. End Sub
复制代码
回复

使用道具 举报

327

主题

3264

回帖

3641

积分

荣誉版主

积分
3641
发表于 2002-5-5 22:22:45 | 显示全部楼层
厉害,厉害,呵呵
回复

使用道具 举报

43

主题

917

回帖

1361

积分

金牌会员

积分
1361
发表于 2002-5-12 13:30:48 | 显示全部楼层
are you sure this can run???
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|海浩社区

GMT+8, 2025-9-17 23:52 , Processed in 0.105058 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表