I have simple MFC legacy application.
I need to create some 5 new screens with very nice GUI - so i decide to do it with WPF.
I'm using VS 2010
My questions are
I don't see any possible to create WPF library in creating new project menu.
How can i import the WPF Dll that i will create into the MFC ?
How can i create an instance of the WPF form MFC and make the Form 'DoModol()' call ?
Related
My Project Consists of Four Items
C# DLL Which Exposes a COM Interface via Interop
A WPF Control which contains an Instance of an exposed class in 1
A Winform ActiveX which hosts the WPF control in 2 using ElementHost
An MFC Dialog Application using the Control from 3
The Winform ActiveX (3) exposes the class instance from 1 via a function in 2. I wish to access this class instance from the MFC dialog application through the ActiveX. I have looked around and found you can do this using CWinFormControl. However I am not at liberty to recompile the MFC app using /clr. Therefore I cannot use CWinFormControl.
I can access the class in 1 via COM from the MFC app and run all the functions etc however the class is a different instance as the DLL is loaded in its own space.
The ActiveX works well and displays all the WPF data nicely.
So the question is how do I get a pointer to the ActiveX control from within the MFC app without using CWinFormControl?
I have tried importing the TLB from the ActiveX and attempting to create a "Variable" for it in the Class wizard but it reports that the TLB is unavailable. I have also tried directly creating a DDX entry by manually creating a variable but DDX doesn't allow pointers.
Any ideas?
The Question is basically trying to access a Winform ActiveX Control in MFC without having to use clr or managed C++.
For anyone interested in the answer to this question here is how I solved it. First off you have to dynamically create the ActiveX and place it your self.
In Your MFC Dialog header add a CWnd
CWnd m_MyActiveX;
In your MFC Cpp dynamically create the Control
m_MyActiveX.CreateControl("MyActiveX.ProgId","",WS_VISIBLE,prect,this,5000);
NOTE: you can find the progid in your Winform ActiveX attributes
[ProgId("MyActiveX.ProgId")]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
Next Grab the IUnknown and QueryInterface for the COM Object You need
IOleObjectPtr pOleObj(m_MyActiveX.GetControlUnknown ());
if (pOleObj != NULL)
{
MyCOMObject::IWpfHostPtr host;
pOleObj.QueryInterface(__uuidof(MyCOMObject::IWpfHostPtr),&host);
MyCOMWPFControl::IWpfControl wpf;
host->GetWpfControl ( &wpf );
MyInternalCOMObject::ICoolObject internal;
wpf->GetInternalObject ( &internal );
internal->AndAPartridgeInaPearTree ();
}
NOTE: The Actual Winform ActiveX must derive from some known Interface
public partial class WpfHost : UserControl, IWpfHost
Using this Technique you successfully host WPF Controls on your Legacy MFC Applications and communicate with them via COM without resorting to Managed C++
I am developing a Windows Form Application in Visual Studio 2008 (C#)
And I want to add Style to the items.
I have been investigating a few ideas about it but I have not found an example about how to do it. Is it really possible?
My app looks like:
But I really want to add more style in buttons, textboxs and other items I have:
My boss insists on using Visual Studio 2008.
To do this without purchasing anything else, you could create your own custom button and text box controls, either from scratch or as controls derived from the existing windows forms controls and then overriding OnPaint etc. Take a look at what's been done here:
http://dotnetrix.co.uk/button.htm
You could also investigate third party options.
Or, use WPF if that's a possibility as others have said. I'd push for WPF! If there's an existing WinForms Code base you can always host WPF Elements in WinForms. See:
Walkthrough: Hosting a Windows Presentation Foundation Control in Windows Forms
IF you wana to use Winforms than you have to buy this one for example:
http://devcomponents.com/
You have to bind the new assemblies in your application that is not a lot of work!
But better way do that with WPF
http://wpftutorial.net/DataGrid.html
I Have i tabbed application called test.exe , and I need to create a new process every time I create a new tab ( something like IE8 do. ).
So if I have 3 tabs opened, I have 3 test.exe process started.
I see many example but nothing with tabpages..
Using MAF (Managed Add-in Framework) with WPF, you can create a Control on a different AppDomain.
That means, you can create these controls on different processes. Try looking into that.
If you are using Windows Forms, there is also a way to get these WPF controls to Windows Forms controls.
It will be a complex solution involving a bunch of technologies you may have to learn. But hey, you get each tab in different processes.
References:
Add-ins and Extensibility
Managed AddIn Framework (System.AddIn) with WPF
Kent Boogaart on MAF
Source Code for Matthew MacDonald's book Pro WPF has a decent example solution you can look into.
At present we host a number of WPF controls in a WinForms application. The application is started using the System.Windows.Forms.Application.Run(...) method and WPF controls hosted using the ElementHost.
In a normal WPF application I'd define a System.Windows.Application object (App.xaml) and call run on it. Normally any application level WPF resources would go in there. We don't have this.
How can I specify application level resources for the WPF controls but still run as a WinForms app?
In a hosted environment you do not have easy access to the Application, Dr WPF has a couple of methods for working in a hosted scenario at http://drwpf.com/blog/2007/10/05/managing-application-resources-when-wpf-is-hosted/.
I am personally using his SharedResources class in a work project, VB6 Form hosting Winforms UserControl hosting ElementHost hosting WPF UserControl with a Application wide theme, for the WPF controls.
If you host WPF controls within a WinForms application you do not have the Applicationobject which hosts the application-wide resources. The trick is to create such a object, load your global resources and merge them into the ResourceDictionary.
Here is an example of this code:
http://www.snippetsource.net/Snippet/26/load-application-level-resources-in-winforms-hosted-wpf-controls (Link fixed)
Is it possible loading C# form (or C# application) into ActiveX control? I know how to load ActiveX control to C# form....
You can call a .Net form in VB6 (with Interop Forms Toolkit 2.0), and you can use VB6 to create an ActiveX so my guess is that it is possible.
I have also heard of ppl used forms created from .net-dlls and den using setparent-api and got it to act as a child to vb6-form.
All in all, yes it seems possible to load an C#-form in an activeX control.
Interop Forms Toolkit 2.0: display .NET Winforms in VB6 Applications
http://hubpages.com/hub/Interop_Forms_Toolkit_20
And someone using SetParent, not a solution but from this its easy to google away to other solutions.
http://www.eggheadcafe.com/forumarchives/NETFrameworkinterop/Oct2005/post24062147.asp