Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello

I have a MDI based rather huge application that has plugin Architecture.
The plugins MFC unmanaged DLLs that bring many unmanaged dialog(CDialog base calls).
I am planning to initially only build the main GUI framework in WPF and keep the plug ins still in MFC, and have Managed wrapper dll which enables me to call this dialog in a managed application.

Slowly change 100+ plugin we have over the period of time.

I would like to have new application also a MDI with docking support. So I am planning to use 3rd part libraries from ActiPro and Syncfusion.

My question is

1) How can I add / remove menu items in a WPF application based on the need of the plug in that is loaded ?

2) How will I able to dock my MFC Dialogs in a WPF application as if they were created using WPF.

Any help is greatly appreciated.

Shashi
Posted
Comments
Sergey Alexandrovich Kryukov 22-Aug-11 21:12pm    
Why would you do such thing? This is the invitation for tons of troubles.
--SA

1 solution

This would be so unpleasant head-breaking exercise with so little use so I would advise you to avoid it by all means. The result would be ugly, absolutely non-portable and very hard to maintain.

First, there is not way to insert a MFC windowed control in a WPF host control. Generally, WPF has almost nothing to do with windows. WPF controls are not windows, with rare exclusion.

So, first you need to integrate WPF with System.Windows.Forms which can provide controls for hosting some external Windows. So, you need to use WPF to System.Windows.Forms interoperation layer. Read Walkthrough: Hosting a Windows Forms Control in WPF: http://msdn.microsoft.com/en-us/library/ms751761.aspx[^]. The solution is to use System.Windows.Forms.Integration.WindowsFormsHost, see http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx[^].

Now, you can insert some System.Windows.Forms control, such as Panel, in WPF window. When you do it, you can PInvoke Windows API SetParent using the panel handle and the handle of you MCF window. See http://msdn.microsoft.com/en-us/library/ms633541%28v=vs.85%29.aspx[^]. You will need to adjust MFC window styles the way it behaves nicely as a child window of the panel. One problem is that the panel cannot know that it is a parent of some external window, from .NET standpoint.

When you have all that, you have a change to build a monster using WPF, System.Windows.Forms and MFC at the same time. Don't think it will help you much. The biggest problem is MFC. How to organize interoperation between native MFC code and .NET? The only way is P/Invoke; and you cannot pass any classes. Basically, you can only P/Invoke static functions with primitive types common between .NET and unmanaged code. On this level, it is extremely difficult to organize complex cooperation between component which is usually required by UI development.

Now, "docking MDI". In a strict sense of MDI, there is no docking support or anything like that. This is some old and discouraged UI design which you don't really know. Also, MDI is not supported by WPF (thanks goodness :-)).

By "MDI" you probably mean something else — modern interface with multiple docking containers (none of them are windows or controls). You can try AvalonDock; see http://avalondock.codeplex.com/[^].

Overall, I don't see any sense in this activity. Chances are, you can upgrade your MFC application to your new requirement without using .NET and write a brand new .NET application doing the same using less effort and development time than you would take for your "integration" project. I'm not sure you will complete such project at all.

Seriously, think if you can avoid it.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900