需要什么钩子来临时阻止 Office Clipboard Listener 接收剪贴板窗口消息?

问题描述

我想暂时阻止 Microsoft Office 中的“Office 剪贴板”接收任何与剪贴板相关的 Windows 消息,以阻止它收集我的复制操作。根据此网站 (http://www.benf.org/excel/officeclip/),此剪贴板基于 OleClipboard,并使用“SetClipboardListener”将自己注册为剪贴板侦听器,以接收有关剪贴板更改的消息(并随后最多存储 24 个复制的项目)。

所以在我的 VSTO 插件中,我尝试基于 WH_GETMESSAGE 设置一个 SetwindowsHookEx。然后我想拦截与剪贴板相关的消息(WM_DRAWCLIPBOARD、WM_CLIPBOARDUPDATE),并根据这篇文章How to discard some messages for a window?)将它们设置为 WM_NULL,这样 Office 剪贴板就不会收到我的操作通知

我尝试了以下代码,但没有收到任何剪贴板消息。我做错了什么或者我应该尝试什么其他方法?也许可以获取 Office 剪贴板窗口的句柄并使用其他一些钩子,但我不知道采取什么方法或如何识别此窗口的句柄。

' Hook procedure callback type.
Private Delegate Function HookProc(ByVal nCode As Integer,ByVal wParam As IntPtr,ByVal lParam As IntPtr) As Integer

messageHookProcedure = New HookProc(AddressOf MessageHookProc)
hookHandle = SetwindowsHookEx(WH_CALLWNDPROC,messageHookProcedure,CType(0,IntPtr),GetCurrentThreadId())

Private Function MessageHookProc(ByVal nCode As Integer,ByVal lParam As IntPtr) As Integer

    ' Per docs,if nCode < 0,the hook procedure must pass the 
    ' message to CallNextHookEx function without further processing
    ' and should return the value returned by CallNextHookEx. 
    If nCode < 0 Then
        Return CallNextHookEx(hookHandle,nCode,wParam,lParam)
    Else

        ' Only process the message if it has not already been 
        ' removed from the queue.
        'If wParam.ToInt32() = PM_norEMOVE Then
        '    ' The lparam that Windows passes us is a pointer to a 
        '    ' MSG struct.
        Dim msg As MSG = CType(Marshal.PtrToStructure(lParam,GetType(MSG)),MSG)
        If msg.message = WM.DRAWCLIPBOARD Then
            System.Windows.Forms.MessageBox.Show("WM_DRAWCLIPBOARD")
        End If

        ' Ensure that we don't break the hook chain.
        Return CallNextHookEx(hookHandle,lParam)
    End If

End Function

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...