microsoft / WPF-Samples

Repository for WPF related samples
MIT License
5.15k stars 3.21k forks source link

WPFHostingWin32Control: cannot handle OnKeyDown events #664

Open juanmanzanero opened 1 month ago

juanmanzanero commented 1 month ago

Issue related to: https://github.com/microsoft/WPF-Samples/tree/main/Migration%20and%20Interoperability/WPFHostingWin32Control

Hello,

Thank you for this very complete solution to hosting a Win32 inside WPF. I am running into an issue: I want to handle Key Down/Up events ocurring inside the Win32 but I am failing to do so. These seem to get lost somewhere as I do not receive them in the 'WndProc' override

        protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
                case (0x0100):
                case (0x0101):
                case (0x0102):
                case (0x0103):
                case (0x0104):
                case (0x0105):
                case (0x0106):
                case (0x0107):
                case (0x0109):
                    Trace.WriteLine("I am receiving keyboard inputs!");
                    break;
            }
            handled = false;
            return IntPtr.Zero;
        }

I happens the same with Mouse-related messages. Can someone explain to me what's missing?

Cheers