1
我在使用Acrobat ActiveX的應用程序中顯示PDF文檔。 我想知道是否可以禁用右鍵單擊PDF文檔?如何禁用Wpf中的acrobat reader contextmenu?
我在使用Acrobat ActiveX的應用程序中顯示PDF文檔。 我想知道是否可以禁用右鍵單擊PDF文檔?如何禁用Wpf中的acrobat reader contextmenu?
我以前的解決方案沒有工作,所以還有一個解決方案。您只需在接收鼠標通知的子窗口上設置鼠標鉤子。
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);
}
我做了同樣的事情,但WM_RBUTTONDOWN事件根本沒有啓動。我不知道爲什麼。 – Pers 2012-02-05 09:40:02
@r r,我用另一個可行的解決方案更新了我的答案。 – Joulukuusi 2012-02-05 20:22:32
謝謝man.it非常有幫助。 – Pers 2012-02-05 23:04:32