Mixing MFC and WPF: Modal Dialogs

I am adding C # WPF dialogs to an existing C ++ MFC application using the C ++ / CLI interface layer. Everything works for me, but I have problems with modality. For instance:

  • The MFC application shows the WPF dialog using ShowDialog. Works as expected.
  • This WPF dialog box displays the MFC dialog using DoModal. The WPF dialog is hidden behind the base C ++ application and is not disabled unless I manually changed IsEnabled. Not perfect, but it works.
  • Now this MFC dialog is closed. Now, for some reason, the underlying MFC application is turned on when it should be turned off because the WPF dialog was not closed. This is bad as it now allows the user to do crazy things while the WPF dialog is still open.

I have a feeling that it will work better if I can correctly establish parent dialogs. But so far I have not been able to set the parent MFC dialog as a WPF dialog, or vice versa. And I don’t even know if that will fix it.

Any ideas?

+3
source share
2 answers

When opening CDialog, the trick is to use WindowsInteropHelper to get the parent WPF HWND dialog. You can then use CWnd :: Attach to port this HWND to the CWnd class to go to the CDialog constructor.

, CDialog, . SetParent , . CDialog, m_wndParent, , , . !

- WPF MFC " ". .

+4

WPF HwndSource, WPF? , :: SetParent WPF, HwndSource.Handle .

+2

Source: https://habr.com/ru/post/1699296/


All Articles