AxAcroPDF吞咽键,如何让它停止? [英] AxAcroPDF swallowing keys, how to get it to stop?

查看:337
本文介绍了AxAcroPDF吞咽键,如何让它停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AxAcroPDF会在所有与键相关的事件获得焦点后立即将其删除,包括快捷键,按键等。我添加了一个消息过滤器,也没有获取任何与键相关的消息。

The AxAcroPDF swallows all key-related events as soon as it gets focus, including shortcuts, key presses, etc. I added a message filter, and it doesn't get any key-related messages either. It's a COM component, could that be relevant?

在控制开始吞下它们之前,是否有任何方法捕获它们?

Is there any way to catch these before the control starts swallowing them?

推荐答案

Hans是正确的,Acrobat Reader生成两个子代AcroRd32进程,您无法从托管代码中直接访问它们。

Hans is correct, the Acrobat Reader spawns two child AcroRd32 processes which you have no direct access to from within your managed code.

我已经尝试过这一点,你有三个可行的选择:

I have experimented with this and you have three viable options:


  1. 钩子,然后寻找并筛选/响应发送到您的孩子AcroRd32窗口的WM_SETFOCUS消息。您可以使用包装程序库(如下所示)从C#中完成其中的一些操作: http://www.codeproject.com/KB/system/WilsonSystemGlobalHooks.aspx

  1. You can create a global system hook, and then look for and filter out / respond to WM_SETFOCUS messages sent to your child AcroRd32 windows. You can accomplish some of this from within C# by using a wrapper library, such as the one here: http://www.codeproject.com/KB/system/WilsonSystemGlobalHooks.aspx

您还需要识别正确的进程,因为可能有多个您的应用程序的一个实例或AcroRd32的其他实例。这是最确定的解决方案,但是因为您的应用程序现在将过滤发送到现有的每个窗口的消息,我通常不推荐这种方法,因为那样您的程序可能会对系统稳定性产生负面影响。

You also need to identify the correct processes as there may be more than one instance of your application, or other instances of AcroRd32. This is the most deterministic solution, but because your application will now be filtering messages sent to every single window in existence, I generally don't recommend this approach because then your program could negatively affect system stability.

查找备用PDF查看控件。请参阅以下几个商业组件的解答: .net PDF查看器控件,或者滚动您自己的: http://www.codeproject.com/KB/applications/PDFViewerControl.aspx

Find an alternate PDF viewing control. See this answer for a few commercial components: .net PDF Viewer control , or roll your own: http://www.codeproject.com/KB/applications/PDFViewerControl.aspx

找到可接受的黑客。根据您的应用程序的稳健性,下面的代码可能是合适的(它适用于我的情况):

Find an acceptable hack. Depending on how robust your application needs to be, code such as the following may be suitable (it was suitable for my case):

DateTime _lastRenav = DateTime.MinValue;

public Form1()
{
    InitializeComponent();

    listBox1.LostFocus += new EventHandler(listBox1_LostFocus);
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    axAcroPDF1.src = "sample.pdf";  //this will cause adobe to take away the focus
    _lastRenav = DateTime.Now;
}

void listBox1_LostFocus(object sender, EventArgs e)
{
    //restores focus if it were the result of a listbox navigation
    if ((DateTime.Now - _lastRenav).TotalSeconds < 1)
        listBox1.Focus();
}


这篇关于AxAcroPDF吞咽键,如何让它停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆