混合MFC和WPF:模态对话框 [英] Mixing MFC and WPF: Modal Dialogs

查看:160
本文介绍了混合MFC和WPF:模态对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C ++ / CLI界面层将C#WPF对话框添加到现有的C ++ MFC应用程序。我有事情工作,除了我有一个模态的问题。例如:

I'm adding C# WPF dialogs to an existing C++ MFC app, using a C++/CLI interface layer. I've got things working, except I'm having a problem with modality. For example:


  1. MFC应用程序使用ShowDialog显示一个WPF对话框。

  2. WPF对话框显示使用DoModal的MFC对话框。 WPF对话框隐藏在基本C ++应用程序后面,除非我手动更改IsEnabled,否则不会禁用。不理想,但它工作。

  3. 现在,该MFC对话框关闭。现在由于某种原因基本MFC应用程序是启用,当它仍然应该禁用,因为WPF对话框没有被关闭。这很糟糕,因为它现在允许用户在WPF对话框仍然打开时做疯狂的事情。

我有一种感觉将更好地工作,如果我可以正确设置父对话框。但到目前为止我还没有能够设置一个MFC对话框的父对象作为WPF对话框,反之亦然。

I have a feeling that it would work better if I could set parent dialogs correctly. But so far I havent been able to set an MFC dialog's parent as a WPF dialog, or vice versa. And, I don't even know if that'd fix it.

任何想法?

推荐答案

打开CDialog时,诀窍是使用WindowsInteropHelper获取父WPF对话框的HWND。然后,你可以使用CWnd :: Attach将CWND类中的HWND包装到CDialog的构造函数中。

When opening a CDialog, the trick is to use a WindowsInteropHelper to get the parent WPF dialog's HWND. Then, you can use CWnd::Attach to wrap that HWND in a CWnd class to pass to the CDialog's constructor.

我遇到的问题是,我已经有了CDialog构造,但尚未显示。只有当目标子窗口已经具有有效句柄时,才能使用SetParent的各种版本。我不得不在我的CDialog类中写一个新的函数来设置m_wndParent,这是它用作父,当它终于创建对话框。然后一切都很好!

The problem I had was that I already had the CDialog constructed., but not yet displayed. The various versions of SetParent can only be used if your target child window already has a valid handle. I had to write a new function in my CDialog class to set m_wndParent, which is what it uses as the parent when it finally creates the dialog. Then everything works great!

从MFC对话框创建WPF对话框只是工作。这是神奇的。

Somehow creating WPF dialogs from MFC dialogs "just works". It's magic.

这篇关于混合MFC和WPF:模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆