Search code examples
winformsmfcaccelerator

Detecting keyboard shortcuts in WinForm swallowed by host mfc accelerators


I have a MFC MDI app which defines Ctrl-F as a keyboard accelerator. This app hosts a WinForm dialog. My problem is I want to catch Ctrl-F from this child WinForm dialog but the MFC mainframe seems to be swallowing it.

  • I can detect other keyboard shortcuts in the WinForm dialog, if they are not defined in the accelerators table
  • If the edit dialog was MFC too, I think I could define and load an accelerator for this dialog too, and then use ProcessMessageFilter
  • in WinForm i've tried both overriding ProcessCmdKey and listening KeyDown events to no avail

Do you think there is a way to receive those key press in the WinForm child?


Solution

  • I've found a solution that works. When showing the c# WinForm, use the overload

    Form.Show(IWin32Window owner)
    

    and pass the MFC mainframe Hwnd as the owner. Now everything is working as expected.