word.app: 如何获取鼠标点击事件?

dafu2003 2010-04-08 08:06:44
现创建一个 word.application, 打开了一个文档,
现需要获取用户点击鼠标后鼠标坐在位置的单词,并对其进行处理。
但发现无法切取鼠标事件。

谁知道如何做?谢谢!


没法,系统提示只能发表30分以内的帖子。本来打算给100分的。
...全文
170 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
biiiiiiird 2011-05-29
  • 打赏
  • 举报
回复
您好,可以发一个dsoframer控件给我吗?
刚好我不需要 捕捉这个事件。
呵呵。
530010248@qq.com
bcrun 2010-04-09
  • 打赏
  • 举报
回复
还会这样啊,你的这个dsoframer是在哪下载的啊,带源代码吗。另外能把你调用部分的代码发上来吗?
dafu2003 2010-04-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 bcrun 的回复:]
会不会是因为dsoframer打开的新文档是在新的Word实例中打开的,即一个新的Word.Application,可在任务管理器中留意一下是否新开了Word进程
[/Quote]

我估计可能也是这种情况,但是我把word.application的那个变量重新指向这个新打开的word,也不起作用了。
bcrun 2010-04-09
  • 打赏
  • 举报
回复
会不会是因为dsoframer打开的新文档是在新的Word实例中打开的,即一个新的Word.Application,可在任务管理器中留意一下是否新开了Word进程
dafu2003 2010-04-09
  • 打赏
  • 举报
回复
程序的目的就是浏览office文档。
加上事件处理的目的,是想在用户点鼠标后,给鼠标所在的词汇一个单词解释。
dafu2003 2010-04-09
  • 打赏
  • 举报
回复
在最后那段打开文档部分后加上:
set wordApp=FramerControl1.activeDocument.application
也不起作用了。
dafu2003 2010-04-09
  • 打赏
  • 举报
回复
我的dsoframer是网上下载的2.2版本,没源程序,估计基本部分与其他版本不会有什么区别。
我的调用部分很简单,程序分布在一个类中的很多部分。

Private Sub wordApp_WindowSelectionChange(ByVal Sel As selection)
Dim vWord As Range, s As String, ex As String
On Error Resume Next
If Sel.Words.count > 0 Then
s = Sel.Words(1).Text
ex = getExplainStr(s)
If ex <> "" Then
showmsg ex
End If
End If
errr:
End Sub

上面这个是事件处理。

下面的是创建dsoframer:

Private Sub LoadOfficeControl()
Dim s As String
On Error GoTo errr
' Set FramerControl1 = s_form.Controls.Add("DSOFramer.FramerControl.1", "FramerControl1") '
Set FramerControl1 = s_form.Controls.add("DSOFramer.FramerControl", "FramerControl1" & CStr(ctlNID), Picture3) '
If FramerControl1 Is Nothing Then
GoTo errr
ElseIf docIsAvailable Then
FramerControl1.Titlebar = False
#If MANAGER = 0 Then
' FramerControl1.Menubar = False
FramerControl1.Toolbars = True
#Else
' FramerControl1.Menubar = True
FramerControl1.Toolbars = True
#End If
FramerControl1.Top = Screen.Height * Screen.TwipsPerPixelY
FramerControl1.left = Screen.Width * Screen.TwipsPerPixelX
' FramerControl1.FrameHookPolicy = dsoSetOnFirstOpen
' Set FramerControlx = FramerControl1.object
doc_OK = True
Else
GoTo errr
End If
Exit Sub
errr:
doc_OK = False
Set FramerControlx = Nothing
If ctlNID < 10 Then
MsgBox "FramerControlx-OCX 没找到或者MS office 不可用!" & vbCrLf & _
"需要安装 Microsoft DSOFramer 控件与MS office, 浏览器才能浏览MS Office类型书籍!"
Else
showmsg "FramerControlx-OCX 没找到或者MS office 不可用! 需要安装 Microsoft DSOFramer 控件与MS office, 浏览器才能浏览MS Office类型书籍!"
End If
End Sub

Public Function docIsAvailable() As Boolean
Dim s As String, cb As Object
On Error GoTo errr
'Set cb = GetObject(, "Word.Application")
' If cb Is Nothing Then
Set cb = CreateObject("Word.Application")
If Not (cb Is Nothing) Then
docIsAvailable = True
Set cb = Nothing
End If
errr:
End Function

下面的是打开文件的部分:
If doc_OK And cfp.isDocLiked(gs) Then
stopVoice
' FramerControl1.Close
docWinShow = True
setCtlOff FramerControl1
FramerControl1.Move 0, 0, formRect.w, formRect.h
FramerControl1.Open ftmp, (Not docEdit)
setFCFormat FramerControl1
end if

setCtlOff FramerControl1 就是关闭窗口上其他控件,显示FramerControl1。
setFCFormat FramerControl1 就是设置文档的显示格式。
这两个于事件处理没关系。
dafu2003 2010-04-08
  • 打赏
  • 举报
回复
谢谢楼上的,你的解答完全正确。
现在还有点问题:
我的word是由dsoframer打开的,经测试,只有第一次打开时有效,
当dsoframer再打开新的文档时,事件就不起作用了?有什么解决办法没有?


bcrun 2010-04-08
  • 打赏
  • 举报
回复
对了,访问插入符所在位置的单词

Private Sub vWordApp_WindowSelectionChange(ByVal Sel As Selection)
Dim vWord As Range
For Each vWord In Sel.Words
Debug.Print vWord.Text
Next vWord
End Sub
bcrun 2010-04-08
  • 打赏
  • 举报
回复
此处一般不是用鼠标事件,而是用WindowSelectionChange的,参考

Option Explicit

Private WithEvents vWordApp As Word.Application

Private Sub InitApp()
Set vWordApp = Application
End Sub



Private Sub vWordApp_WindowSelectionChange(ByVal Sel As Selection)

End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧