views:

28

answers:

1

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?

A: 

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);
}
JeffN825
I have already overridden the WndProc looking for the message and it never receives it, so this wouldn't work. If I register as an IMessageFiler I do see it in the PreFilterMessage, and interestingly enough the window handle it displays appears to be correct if I find the window in Spy++, but it still doesn't make it up to my subclassed proc.
Toji
If your form is stealing focus and you never hit the WndProc method, there is something wrong. Are you sure you're handling WndProc on the specific control that is stealing focus?
JeffN825
I'm not 100% certain, but considering that the program constists of a form, a button, and my popup there's not too many options to look at. :)
Toji
Small update: I've now watching the messages for every single window that I'm instantiating (the form, the button, the popup panel, and the edit box) and the only place I ever see my ESC keydown is in the PreMessageFilter, which appears to indicate that .NET is suppressing the message before it ever gets sent to any windows. :P
Toji