如何在Wpf中禁用acrobat reader contextmenu?

时间:2012-02-02 13:17:10

标签: wpf acrobat right-click

我正在使用Acrobat ActiveX在我的应用程序中显示PDF文档。 我想知道是否可以禁用右键单击PDF文档?

1 个答案:

答案 0 :(得分:0)

我以前的解决方案不起作用,所以还有另外一个。您只需要在接收鼠标通知的子窗口上设置鼠标挂钩。

public class AcrobatReader : AxAcroPDF
{
    private const int WH_MOUSE_LL = 14;
    private const int WM_RBUTTONDOWN = 0x0204;

    private static LowLevelMouseProc _proc = HookCallback;
    private static IntPtr _hookID = IntPtr.Zero;

    public AcrobatReader()
    {
        _hookID = SetWindowsHookEx(WH_MOUSE_LL, _proc, FindWindow(null, "avpageview"), 0);
    }

    ~AcrobatReader()
    {
        if (_hookID != IntPtr.Zero)
        {
            UnhookWindowsHookEx(_hookID);
            _hookID = IntPtr.Zero;
        }
    }

    private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
    {
        if (nCode >= 0 && (IntPtr)WM_RBUTTONDOWN == wParam)
        {
            return new IntPtr(1);
        }
        return CallNextHookEx(_hookID, nCode, wParam, lParam);
    }

    private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);

    [DllImport("user32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool UnhookWindowsHookEx(IntPtr hhk);

    [DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
}