Winforms 窃取 COM 组件的击键?
我有一个 C++ ATL COM 组件,它显示一个弹出窗口(普通的 Win32,使用 WS_POPUP 样式),允许用户输入一些搜索信息。该组件已经针对 VB6 表单进行了相当广泛的测试(主要是为了便于调试),但我们希望将其与 .NET winforms 一起使用。
当从 winforms 环境调用该组件时,我们发现的奇怪的事情是某些击键不再到达我们的弹出窗口。例如:我们在弹出窗口上创建了一个编辑框的子类,以侦听 ESC 键并关闭弹出窗口。在 VB6 中,这效果很好,但在 winforms 中,弹出窗口永远不会收到 ESC 的 keydown 事件(对于其他键,例如标准字母数字,它会收到)。
该组件的使用非常简单,但我将在这里提供一个快速示例来避免出现任何问题:
public partial class Form1 : Form
{
CustomPopup panel;
public Form1()
{
panel = new CustomPopup(); //This is the COM object
}
private void button1_Click(object sender, EventArgs e)
{
Point p = this.PointToScreen(button1.Location);
// Display the popup, which gives focus to a child WC_EDIT field
panel.ShowPopupAt(p.X, p.Y);
}
}
如您所见,没有太多内容。那么,关于 winforms 中的什么正在消耗我们的击键以及我们如何让它停止,有什么想法吗?
I have a C++ ATL COM component that displays a popup window (plain ol' Win32, using the WS_POPUP style) which allows the user to input some search information. This component has been tested pretty extensively against a VB6 form (primarily for ease of debugging), but we want to use it with .NET winforms.
The curious thing that we found when calling the component from a winforms environment is that certain keystrokes no longer make it through to our popup window. For example: we have subclassed an edit box on the popup to listen for the ESC key and close the popup. In VB6 this works great, but in winforms the popup never receives the keydown event for ESC (it does for other keys, like standard alphanumerics).
Use of the component is pretty trivial, but I'll throw up a quick sample here to head off any questions:
public partial class Form1 : Form
{
CustomPopup panel;
public Form1()
{
panel = new CustomPopup(); //This is the COM object
}
private void button1_Click(object sender, EventArgs e)
{
Point p = this.PointToScreen(button1.Location);
// Display the popup, which gives focus to a child WC_EDIT field
panel.ShowPopupAt(p.X, p.Y);
}
}
As you can see, not much to it. So, any ideas on what in winforms is eating our keystrokes and how we can tell it to stop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试抑制 WND 消息的 Windows 窗体处理(在窃取消息的控件/窗体中):
Try suppressing the Windows Forms processing of the WND message (in the control/form stealing the message):