We are using a third party graphics application that uses MFC and requires an MFC window passed to it to populate with graphics. We want to display this in a .NET graphic environment with other Forms. We have a desktop that accepts any Form class to manage. How can we display the MFC window in a .NET form for inclusion in the desktop? Obviously, since this is third party software, recoding in .NET is not an option. I am reading two...
questions: first a third-party 'application' that accepts MFC windows from callers; and second, how to display an MFC window in a .NET form.
The first problem is a bit of trouble since your code is managed but the application will only accept an MFC window. If it must be an MFC window (say a CWnd derived object), then you'll need to write a native MFC DLL that creates an MFC window (warning: this DLL will may have to use the same version of MFC the third-party software uses). Your managed code can call your native code to create and return the MFC window and then opaquely pass the MFC window by passing its CWnd pointer to the 3rd-party software. If the third-party software only requires an HWND, you may be able to get away with creating a simple managed control. Grab managed control's HWND from the Handle property and pass that to the 3rd-party software.
The second problem is less trouble. Let's say the third-party software returns an HWND. You can easily use the NativeWindow class to 'attach' to the HWND using the AssignHandle method. If the third-party software returns a CWnd derived pointer, you'll again need unmanaged code to get the HWND from the CWnd before 'attaching' with the NativeWindow object.
Dig deeper on Win Development Resources
Related Q&A from Berni McCoy
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.