开发者

Winforms stealing keystrokes from COM component?

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 compo开发者_开发知识库nent 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?


Try suppressing the Windows Forms processing of the WND message (in the control/form stealing the message):

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_LBUTTONDOWN || m.Msg == WM_LBUTTONUP || m.Msg == WM_LBUTTONDBLCLK
       )
    {
        return;
    }
    base.WndProc(ref m);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜