Ask the Expert

Third-party app that accepts MFC windows from callers; how to display an MFC window in a .NET form

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.

This was first published in March 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: