AxAcroPDF 会在获得焦点后立即吞下所有与键相关的事件,包括快捷键、按键等.我添加了一个消息过滤器,它也没有收到任何与键相关的消息.它是一个 COM 组件,这可能是相关的吗?
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:
您可以创建一个全局系统挂钩,然后查找并过滤/响应发送到您的子 AcroRd32 窗口的 WM_SETFOCUS 消息.您可以使用包装库在 C# 中完成其中的一些操作,例如此处的一个:http://www.codeproject.com/KB/system/WilsonSystemGlobalHooks.aspx
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 Viewer control ,或自己动手: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
找到一个可接受的 hack.根据您的应用程序需要的健壮程度,以下代码可能是合适的(它适合我的情况):
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 吞键,如何让它停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!